Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get public static method of base class?

My base class has a public static method, but when I call typeof(TDerived).GetMethods(BindingFlags.Public |BindingFlags.Static) my method doesn't get returned. (TDerived of course inherits in some way from my base class). I don't have a reference to my base class at the place of this query.
What am I doing wrong?

like image 899
TDaver Avatar asked Apr 15 '11 09:04

TDaver


1 Answers

Use the BindingFlags.FlattenHierarchy flag:

typeof(TDerived).GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)

It is a documented behavior in the Remarks section for Type.GetMethods(BindingFlags) method.

like image 57
Ondrej Tucny Avatar answered Oct 05 '22 23:10

Ondrej Tucny