HI, all,
I just want to invoke an internal method named 'ResolveClientU rl', which
is defined in class System.Web.UI.C ontrol, 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.C ontrol):
//...
MyControl instance = new MyControl();
Type type = instance.GetTyp e();
object[] args = new object[] {"images/test.gif"};
string path = (string)type.In vokeMember("Res olveClientUrl",
BindingFlags.Pu blic | BindingFlags.No nPublic | BindingFlags.In stance |
BindingFlags.Ge tProperty,
null, instance, args);
//...
Actually, I intended to use the type object of MyControl to invoke the inherited
method 'ResolveClientU rl', but an Exception occured, described as "Method
LaserWeb.Presen tation.MyContro l.ResolveClient Url not found." It seems that
reflection didn't search in the inherited members up the class hierarchy,
since 'ResolveClientU rl' is a declared method in the base class Control.
This action, I guess, should only be taken when BindingFlags.De claredOnly
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.De claredOnly flag. Then why? How could
it happen? I was puzzled:( Help!
Regards,
Laser Lu
I just want to invoke an internal method named 'ResolveClientU rl', which
is defined in class System.Web.UI.C ontrol, 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.C ontrol):
//...
MyControl instance = new MyControl();
Type type = instance.GetTyp e();
object[] args = new object[] {"images/test.gif"};
string path = (string)type.In vokeMember("Res olveClientUrl",
BindingFlags.Pu blic | BindingFlags.No nPublic | BindingFlags.In stance |
BindingFlags.Ge tProperty,
null, instance, args);
//...
Actually, I intended to use the type object of MyControl to invoke the inherited
method 'ResolveClientU rl', but an Exception occured, described as "Method
LaserWeb.Presen tation.MyContro l.ResolveClient Url not found." It seems that
reflection didn't search in the inherited members up the class hierarchy,
since 'ResolveClientU rl' is a declared method in the base class Control.
This action, I guess, should only be taken when BindingFlags.De claredOnly
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.De claredOnly flag. Then why? How could
it happen? I was puzzled:( Help!
Regards,
Laser Lu
Comment