Ok I derive a type B from a base class A.
A implements IDisposable explicit but I have to do additional cleanup in B, so I implement IDisposable in B:
interface IDisposable with
member i.Dispose() =
// ... additional work
base.Dispose() // <- want to do but cannot
Question is: how to access the Dispose-method from base?
(base :> IDisposable).Dispose()
yields compiler error: Unexpected symbol ':>' in expression. Expected '.' or other token.
Doing something like
(i :> IDisposable).Dispose()
of course yields a StackOverflowException on runtime – so how can I do this? Sorry but never encountered something like this before…
You’re probably better off putting your clean-up logic in a virtual method and implementing
IDisposableonly once.Since there’s no
protectedaccess modifier, you can use a signature file to makeClosenon-public (or mark itinternal).The
basekeyword can only be used for member access, not standalone. That’s whybase :> IDisposabledoesn’t work.Looking in Reflector,
Disposeonly calls the publicClosemethod. So you could re-implementIDisposableand callbase.Close()instead.You could have this same scenario in C#. Inheritable classes that implement
IDisposableshould provide a way for subclasses to “plug in” to disposal. This is usually done by providing aprotected virtual Dispose(disposing)overload that’s called fromDispose(). For whatever reason,DuplexClientBasedoesn’t follow this convention. Perhaps it was deemed unnecessary given thatDisposemerely forwards toClose.