如何获取实例的通用接口类型?C#如何检查一个类是否实现泛型接口?
假设验证码:
interface IMyInterface<T>
{
T MyProperty { get; set; }
}
class MyClass : IMyInterface<int>
{
#region IMyInterface<T> Members
public int MyProperty
{
get;
set;
}
#endregion
}
MyClass myClass = new MyClass();
/* returns the interface */
Type[] myinterfaces = myClass.GetType().GetInterfaces();
/* returns null */
Type myinterface = myClass.GetType().GetInterface(typeof(IMyInterface<int>).FullName);
但我需要的类型,因为我将它添加到集合。 – 2010-03-26 10:29:46