【发布时间】:2010-11-11 15:25:43
【问题描述】:
我有一个通用接口,比如 IGeneric。对于给定的类型,我想找到一个类通过 IGeneric 实现的泛型参数。
在这个例子中更清楚:
Class MyClass : IGeneric<Employee>, IGeneric<Company>, IDontWantThis<EvilType> { ... }
Type t = typeof(MyClass);
Type[] typeArgs = GetTypeArgsOfInterfacesOf(t);
// At this point, typeArgs must be equal to { typeof(Employee), typeof(Company) }
GetTypeArgsOfInterfacesOf(Type t)的实现是什么?
注意:可以假设 GetTypeArgsOfInterfacesOf 方法是专门为 IGeneric 编写的。
编辑:请注意,我专门询问如何从 MyClass 实现的所有接口中过滤掉 IGeneric 接口。
【问题讨论】:
标签: c# generics reflection