I have a class that implements IDisposable
public class Foo: IDisposable {
public void Dispose() {
// do the disposing
}
}
Then I have a method that uses the class in the following manner:
void Bar() {
using (var f = new Foo()) {
// do whatever
}
}
When the code leaves the using {...} boundary, the Dispose method on the Foo class gets called. How can I detect in the Dispose method whether the code is leaving using block voluntarily or as a result of an exception?