¿Cómo obtener el tipo de interfaz genérica para una instancia?C# ¿Cómo verificar si una clase implementa una interfaz genérica?
Supongamos que este código:
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);
Pero necesito el tipo, porque lo estoy agregando a una Colección. –