Detect variance on generic type parameters of interfaces

Posted by Water Cooler v2 on Stack Overflow See other posts from Stack Overflow or by Water Cooler v2
Published on 2010-05-20T09:27:44Z Indexed on 2010/05/20 9:40 UTC
Read the original article Hit count: 265

Is there a way to reflect on an interface to detect variance on its generic type parameters and return types? In other words, can I use reflection to differentiate between the two interfaces:

interface IVariant<out R, in A>
{
   R DoSomething(A arg);
}


interface IInvariant<R, A>
{
   R DoSomething(A arg);
}

The IL for both looks the same.

© Stack Overflow or respective owner

Related posts about reflection

Related posts about covariance