tags:

views:

44

answers:

2

Hello, 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.

A: 

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

Rune FS
+2  A: 

Try using the BindingFlags.FlattenHierarchy binding attribute. (I haven't tried it myself, so my apologies if I waste your time.)

Marcelo Cantos