我有一个通用接口,称为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接口。
相关链接:查找类型是否实现了泛型接口