C# How to check if a class implements generic interface ?
Posted
by PaN1C_Showt1Me
on Stack Overflow
See other posts from Stack Overflow
or by PaN1C_Showt1Me
Published on 2010-03-26T10:24:37Z
Indexed on
2010/03/26
10:33 UTC
Read the original article
Hit count: 231
How to get generic interface type for an instance ?
Suppose this code:
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);
© Stack Overflow or respective owner