views:

30

answers:

1

I have a situation where I am defining an interface and then using that directly eg:

Dim x as IWhatever = new implementationOfIWhatever()

Which is fine, but implementationOfIWhatever also implements IDispoable so I want to be able to do x.Dispose or ideally Using x but get the error that that this is not declared or must implement IDispoable as IWhatever of course doesn't define Dispose or implement IDispoable.

How can I create the contract that IWhatever will also implement IDispoable or can I not do this and must add .Dispose to my interface and accept I can't use Using.

+2  A: 

Make IWhatever inherit from IDisposable. This will force implementationOfIWhatever to implement the Dispose method, and it will allow you to use IWhatever instances with Using.

Tim Robinson
I knew it would be something simple, I tried thinks like IWhatever implements IDispoable but not inherits.Thanks.
themaninthesuitcase