Cách nhận loại giao diện chung cho một phiên bản?C# Làm cách nào để kiểm tra xem một lớp có triển khai giao diện chung không?
Giả mã này:
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);
Nhưng tôi cần loại, vì tôi đang thêm nó vào Bộ sưu tập. –