You are designing an interface IFoo
public interface IFoo
{
void Bar();
}
Let's say there are five implementations of this interface. Two of those implementations should also implement IDisposable
as they use unmanaged resources. From a caller's perspective, it would be easiest if IFoo
implemented IDisposable
so any IFoo
can be wrapped in a using
block, but of course some of the implementations would then be littered with empty Dispose()
methods. Just curious are there other ways of doing this?
I suspect I'd simply demand IDisposable()
- a no-op Dispose()
isn't a big overhead.
If you can't be sure whether it is disposable, the following is pretty effective:
var mightBeDisposable = GetBlah();
using(mightBeDisposable as IDisposable)
{
// etc
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With