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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
If you want to get hold of all the static members of your direct base type, ie. only the static methods of the class from which the current class inherits, then you can access it through reflection as well.
Your code, from your question, would then become:
Of course, this would only get the static methods of that type. If you want all the static methods of your own type and the base type(s), then go with the FlattenHierarchy option that @Ondrej answered with, much better.
Use the
BindingFlags.FlattenHierarchy
flag:It is a documented behavior in the Remarks section for
Type.GetMethods(BindingFlags)
method.