如何获得基类的公共静态方法? [英] How to get public static method of base class?
本文介绍了如何获得基类的公共静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的基类有一个公共静态方法,但是当我打电话 typeof运算(TDerived).GetMethods(BindingFlags.Public | BindingFlags.Static
),我的方法没有得到回。 (当然TDerived在某种程度上继承我的基类)。我并不在此查询的地方有我的基类的引用。结果
我在做什么错了?
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?
推荐答案
使用 BindingFlags.FlattenHierarchy
标记:
typeof(TDerived).GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
有备注部分一个记录的行为为 Type.GetMethods(的BindingFlags)
方法。
这篇关于如何获得基类的公共静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文