unfortunately I don't so I can't... Paul
-----Original Message----- From: Jason Hagar [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 11:50 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Calling base.base.method in C# weird behaviour or how? Paul, If you have access to the source of B you can write B's and C's Write method as being new instead of override, and then write C as follows: class C:B { public new void Write() { Console.WriteLine("C write"); ((A)this).Write(); } } HTH, Jason Hagar Paul van Brenk wrote: >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] > > > =================================== This list is hosted by DevelopMentor(r) http://www.develop.com You may be interested in Guerrilla .NET, 24 March 2003, in London http://www.develop.com/courses/gdotnet View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŪ http://www.develop.com You may be interested in Guerrilla .NET, 24 March 2003, in London http://www.develop.com/courses/gdotnet View archives and manage your subscription(s) at http://discuss.develop.com