[Mono-dev] Mono-2.8.2 Cross Compiled for ARM processor (Interesting issue with Generics)

Robert Jordan robertj at gmx.net
Tue Mar 1 04:45:12 EST 2011


On 28.02.2011 23:30, Sean Hubbell wrote:
> Given the following example, could someone confirm if this is an issue or
> just my misunderstanding of the methods?
>
> The below is Mono 2.8.2 Cross Compiled for an ARM processor. The issue comes
> up when I would like to do a couple of things with generics:
>
>     public static bool AreEqual<T>(IEnumerable<T>  one, IEnumerable<T>  two)
>          {
>              bool isEquatable =
> typeof(IEquatable<T>).IsAssignableFrom(typeof(T)); // Works: true if generic
> supports the IEquatable<T>  interface.
>
>
>              bool isEquatable = type.IsInstanceOfType(typeof(IEquatable<T>));
> // Does not work: will always return false.

I don't know what "type" is in your code, but IsInstanceOfType
will never return true if the type is a generic definition:

typeof(IEquatable<X>).IsInstanceOfType(IEquatable<T>) == false
for each concrete type X.


Robert




More information about the Mono-devel-list mailing list