我有一個通用接口,比如說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(T型)的實施?
注意:可以假定GetTypeArgsOfInterfacesOf方法是專門爲IGeneric編寫的。
編輯:請注意,我特別要求如何從MyClass實現的所有接口過濾掉IGeneric接口。
相關:Finding out if a type implements a generic interface
好吧,但這涉及到EvontType的IDontWantThis。我不想要EvilType。 –
2009-07-17 08:58:47