vendredi 3 février 2017

Distinguish between a class generic type parameter and method generic type parameter

Given the following example class:

class Foo<T>
{
  void Bar<S>(T inputT, S inputS)
  {
    // Some really magical stuff here!
  }
}

If I am reflecting against method Foo<>.Bar<>(...), and examining the parameter types, say:

var argType1 = typeof(Foo<>).GetMethod("Bar").GetParameters()[0].ParameterType;
var argType2 = typeof(Foo<>).GetMethod("Bar").GetParameters()[1].ParameterType;

both argType1 and argType2 look similar:

  • FullName property is null
  • Name property is "T" or "S" respectively
  • IsGenericParameter is true

Is there anything in the parameter type information that allows me to distinguish that the first argument is defined at the type-level, while the second argument is a method-level type parameter?





Aucun commentaire:

Enregistrer un commentaire