L
Laser Lu
HI, all,
I just want to invoke an internal method named 'ResolveClientUrl', which
is defined in class System.Web.UI.Control, using an instance object of a
type that derives from Control.
Let's see the following code snippet (class MyControl is a sub class that
derives directly from System.Web.UI.Control):
//...
MyControl instance = new MyControl();
Type type = instance.GetType();
object[] args = new object[] {"images/test.gif"};
string path = (string)type.InvokeMember("ResolveClientUrl",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.GetProperty,
null, instance, args);
//...
Actually, I intended to use the type object of MyControl to invoke the inherited
method 'ResolveClientUrl', but an Exception occured, described as "Method
LaserWeb.Presentation.MyControl.ResolveClientUrl not found." It seems that
reflection didn't search in the inherited members up the class hierarchy,
since 'ResolveClientUrl' is a declared method in the base class Control.
This action, I guess, should only be taken when BindingFlags.DeclaredOnly
is specified for invoking a method, otherwise inherited members derived from
base class should be considered. However, in this sample code, it didn't
work I did not pass the BindingFlags.DeclaredOnly flag. Then why? How could
it happen? I was puzzled Help!
Regards,
Laser Lu
I just want to invoke an internal method named 'ResolveClientUrl', which
is defined in class System.Web.UI.Control, using an instance object of a
type that derives from Control.
Let's see the following code snippet (class MyControl is a sub class that
derives directly from System.Web.UI.Control):
//...
MyControl instance = new MyControl();
Type type = instance.GetType();
object[] args = new object[] {"images/test.gif"};
string path = (string)type.InvokeMember("ResolveClientUrl",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.GetProperty,
null, instance, args);
//...
Actually, I intended to use the type object of MyControl to invoke the inherited
method 'ResolveClientUrl', but an Exception occured, described as "Method
LaserWeb.Presentation.MyControl.ResolveClientUrl not found." It seems that
reflection didn't search in the inherited members up the class hierarchy,
since 'ResolveClientUrl' is a declared method in the base class Control.
This action, I guess, should only be taken when BindingFlags.DeclaredOnly
is specified for invoking a method, otherwise inherited members derived from
base class should be considered. However, in this sample code, it didn't
work I did not pass the BindingFlags.DeclaredOnly flag. Then why? How could
it happen? I was puzzled Help!
Regards,
Laser Lu