I have an InfoPath form which I need to conditionally disable it\'s OnChange events. Since it\'s not possible to bind the event handlers after the form has loaded, I\'m forc
No and no. using
is the closest you can get to RAII (more accurately, we are talking about the resource release that follows a RAII-idiom object being destructed).
To answer your points more directly:
IDisposable
(and by extension using
) was created exactly because there is no way to do that in .NET.using
is syntactic sugar that gets compiled as try
/finally
and only requires that the object is IDisposable
, so you cannot distinguish between usage inside a using
statement and out of it.