Given a type instance, how to get generic type name in C#?

Posted by George Polevoy on Stack Overflow See other posts from Stack Overflow or by George Polevoy
Published on 2010-03-15T16:38:19Z Indexed on 2010/03/15 16:39 UTC
Read the original article Hit count: 121

Filed under:
|
|

Given a generic type, including List, Nullable how do i get a generic name for C#?

var t = typeof(Nullable<DateTime>);    
var s = t.GetGenericTypeDefinition().Name + "<" + t.GetGenericArguments()[0].Name + ">";

This yields

"Nullable`1<DateTime>"

, but i need

"Nullable<DateTime>"

.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection