themaninthesuitcase
themaninthesuitcase

Reputation: 4791

Implement IDispoable in an Interface

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.

Upvotes: 1

Views: 106

Answers (1)

Tim Robinson
Tim Robinson

Reputation: 54764

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.

Upvotes: 2

Related Questions