Reputation: 2597
I have task to get static method using reflection like this :
myType.GetMethod("MyMethod",BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod);
In case if class contains MyMethod
all works correctly, but in case if parent class contains MyMethod
I receive null :(. How can I call static method from the parent using reflection like code that I describe above?
Thanks.
Upvotes: 4
Views: 1524
Reputation: 185852
Try using the BindingFlags.FlattenHierarchy
binding attribute. (I haven't tried it myself, so my apologies if I waste your time.)
Upvotes: 6
Reputation: 21742
very simple get the type object that describes the parent class and execute the above code on that object that will give you the MethodInfo object you need. Invoke the methodInfo object passing it an object of myType for the instance parameter
Upvotes: 0