Is it safe to use the using statement on a (potentially) null object? Consider the following example:
using
class Test { IDisposable GetObject
The expansion for using checks that the object is not null before calling Dispose on it, so yes, it's safe.
null
Dispose
In your case you would get something like:
IDisposable x = GetObject("invalid name"); try { // etc... } finally { if(x != null) { x.Dispose(); } }