Cody,
Ok, you got me on a technicality. Internally, yeah, the compiler does some
wierd stuff to make things work.
And, I forgot to say that this was caused by the fact that the method is an
explicit interface method.
But, generically, the VTable is used to lookup virtual functions for a
class. Not an interface. (The "V" in VTable stands for virtual.)
Interfaces do not have virtual methods. Classes do. Interfaces do not have
implementations . Classes do.
In your example, you interchange interface and class; yet they are
distinctly different. (As shown above.)
Yes, when you implement a class, the interface methods in the class are
marked virtual, but final. Hence, you can "new" them, but not override them.
True virtual functions are those that may be overriden. The resaon the are
sealed (marked final) is because there is no inheritence. Unless of course
you implement them in a class, and then inherit from the class. But, then,
unless you mark the method virtual, you still can only new them.
However, in the example, the problem is that the method was declared as an
explicit interface. Internally this is seen as an override, but, it is an
override of an interface which has no implementation. Hence, you get no
inheritence. And, the compiler will not let you call the base method either,
because an interface does not have implementation.
As I pointed out in my other post, the method needs to be declared as a
regular class method to provide implementation inheritence. Since it is
defined explicitly as an interface (no implementation) , the compiler won't
let you call the (as far as it is concerned) non-existent implementation.
Hence, you must resort to hack (reflection) to get at the implementation.
"cody" <de********@gmx .de> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl...
AFAIK, interface methods asre called through a vtable.
If they wouldn't, how would the compiler determine the address of the
method
if I say test.Dispose() where test is of type IDisposible? Test could be
any
class.
Under the hood, interface methods are declared as sealed *and* virtual.
"Frisky" <Fr***********@ NorthPole.Net> schrieb im Newsbeitrag
news:uI******** ******@TK2MSFTN GP09.phx.gbl... Cody,
The problem is that the method is not declared as virtual in the third
party class. Hence, the Dispose method is not virtual. (No VTable) Not the
other
way around.
Frisky
"cody" <de********@gmx .de> wrote in message
news:uk******** ******@tk2msftn gp13.phx.gbl... > Since your implementation of IDisposable.Dis pose() overwrite the original > entry of Dispose in the vtable there is no way to get back the pointer to > the original Dispose method.
> If you find no other solution for your problem you can try with
> reflection.
>
>
> <jo*@martinsoun d.com> schrieb im Newsbeitrag
> news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
>> How can I call a base interface method?
>>
>> class ThirdPartyClass :IDisposable { //I can not modify this class
>> void IDisposable.Dis pose() {
>> Console.WriteLi ne( "ThirdPartyClas s Dispose" );
>> }
>> }
>>
>> class MyClass :ThirdPartyClas s, IDisposable {
>> void IDisposable.Dis pose() {
>> Console.WriteLi ne( "MyClass Dispose" );
>> //base.IDisposabl e.Dispose(); //How can I do this !!!!
>> }
>> }
>>
>
>