mardi 15 novembre 2016

C# Reflection - Delegate in a generic class

// case1
public class A<T> {
    public delegate bool Compare(T a, T b);
}

// case2
public class A {
    public delegate bool Compare<T>(T a, T b);
}

Test(typeof(A<>.Compare));
Test(typeof(A.Compare<>));

void Test(Type type)
{
    // #1
}

My Question:

How to write code in position #1 to tell type is case1 or case2?

It seems there is no difference between

typeof(A<>.Compare).GetGenericArguments()[0]

and

typeof(A.Compare<>).GetGenericArguments()[0]

Thanks!





Aucun commentaire:

Enregistrer un commentaire