在反射某个类型的接口时,发现GetInterfaces获得的接口类不止本类的,还包括父类的,也就是递归获得所有接口。
比如 我定义了一个控件 TreeList : BaseContrl, INodeSubList。 BaseControl是基类,INodeSubList是接口
用GetInterfaces获取的样子却是这样
public class TreeList : BaseControl, IComponent, IDisposable, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject, IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage, IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window, IArrangedElement, IBindableComponent, INodeSubList实际上中间的这些接口都是BaseControl的,有没有什么办法把这些过滤掉,我只要INodeSubList。
比如 我定义了一个控件 TreeList : BaseContrl, INodeSubList。 BaseControl是基类,INodeSubList是接口
用GetInterfaces获取的样子却是这样
public class TreeList : BaseControl, IComponent, IDisposable, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject, IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage, IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window, IArrangedElement, IBindableComponent, INodeSubList实际上中间的这些接口都是BaseControl的,有没有什么办法把这些过滤掉,我只要INodeSubList。
解决方案 »
- RDLC学习资料谁有帮忙推荐1下。帮顶有分!
- 无法将带 [] 的索引应用于“Word.InlineShapes”类型的表达式
- 请教大家,怎么把c++写的[int number[] ; fout.write((char *)(&number), sizeof(number));]文件在c#中打开?
- ImgaeList问题。
- 什么叫‘方法重载’?
- 新手问题:如何保存一个FORM中的所有控件?谢谢
- 关于用c#实现上传word,txt文件内容到数据库中,然后通过调用数据库中的数据在页面中呈现出来。
- 项目比较大,都是新人怎么做? 求大家给点意见!
- 请问C#调用C++/CLR中生成dll,类型转换问题
- c# winform 里面datagridview中的comboxcolumn如何动态赋值
- 奇怪的HttpWebRequest编码问题
- 提示信息,等待15秒后执行怎么处理。
1.父类GetInterfaces2.再用当前类GetInterfaces3.两个相减
foreach (Type inter in inters)
{
InterfaceMapping im = type.GetInterfaceMap(inter);
if (im.TargetMethods.Length > 0 &&
im.TargetMethods[0].DeclaringType == type)
{
Console.WriteLine("Yes");
}
}