Ok, first of all I know this is not supposed to be done,
OO-architecture... design your classes differently etc.
Ok, so we got that out of the way.
I have three classes, all with the method Write() and I would like to
call the A.Write() method from the C.Write() method effectively
bypassing B.Write(). Is this possible in C# using reflection...the code
currently in C.Write() descripes what I have tried allready, except for
base.base.Write() which for obvious reasons i didn't bother with.
Paul
[code]
class A{
public virtual void Write(){
Console.WriteLine( "A write" ); }
}
class B : A{
public override void Write(){
Console.WriteLine( "B write" );
}
}
class C : B{
public override void Write(){
Console.WriteLine( "C write" ); // C.Write()
base.Write(); // base
B.Write()
Type type = typeof( A );
MethodInfo method = type.GetMethod( "Write",
BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.InvokeMethod );
Object obj = (A)this;
Object[] args = null;
method.Invoke( obj, args ); // C.Write()
MethodInfo basemethod = method.GetBaseDefinition();
basemethod.Invoke( obj, args ); // also C.Write()
// but how to call A.Write() from here
}
}
[/code]