【发布时间】:2011-06-04 23:58:41
【问题描述】:
可能重复:
Reflecting over all properties of an interface, including inherited ones?
在尝试从接口接收有关所有方法的信息时,我首先尝试了以下操作:
interface IBaseInterface
{
void SomeMethod();
}
interface ISomeInterface : IBaseInterface {}
Type interfaceType = typeof( ISomeInterface );
BindingFlags allInstanceMembers = BindingFlags.FlattenHierarchy |
BindingFlags.Instance |
BindingFlags.NonPublic |
BindingFlags.Public;
MethodInfo[] methods = interfaceType.GetMethods( allInstanceMembers );
这会导致一个空的方法数组。
我认为问题是扁平化层次结构不适用于接口,但我不确定。在尝试使用 Type.GetInterfaceMap 实现之前,如果有人能确认或解释我做错了什么,那就太好了。
【问题讨论】:
标签: c# reflection