samedi 14 octobre 2017

name of class with generic parameters?

I'm trying to generate code for series of generic classes using T4.

I want to know how to get full class name using reflection?

public class Foo<TFirst, TSecond> {}

var type = typeof(Foo<,>);
var name = type.FullName; // returns "Foo`2"

what I want is full name with actual generic parameter names that I've written

"Foo<TFirst, TSecond>"

Note that they are not known type, as I said I'm generating code using T4, so I want to have exact naming to use it for code generations, as an example, inside generic methods.

I tried this answers but they require to pass known type which is not what I want.





Aucun commentaire:

Enregistrer un commentaire