Curious said:
I'll need something like:
base.base.Show();
However, this doesn't work. The grandparent class name is "BaseForm".
What's the correct syntax to call the "Show" method defined in the
"BaseForm" class?
You can't. And you shouldn't. But the IL hacker in me can't resist
pointing out that you can!
Basically, the idea is to make a non-virtual call to a virtual method
(eugh!). I've included some sample code, but be warned that I've not
tested it and it's late here.
Every time you use this code, an OO purist kills a puppy.
delegate void ShowDelegate();
public void GrandParentShow() {
DynamicMethod show = new DynamicMethod(
"_Show",
null,
new Type[0],
typeof(Program).Module); //This is just a reference to
// your module. You don't have to use typeof(Program)
ILGenerator il = show.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
//You could get the current type and call
//currentType.Parent.Parent instead of
//hardcoding the grandparent
il.Emit(OpCodes.Call, typeof(BaseForm).GetMethod("Show"));
il.Emit(OpCodes.Ret);
ShowDelegate del =
(ShowDelegate)show.CreateDelegate(typeof(ShowDelegate));
del();
}
Alun Harford