.net - Get user-friendly name for generic type in C# -


is there easy way without writing recursive method give 'user friendly' name generic type type class?

e.g. following code want 'list<dictionary<int>>' instead of shorthand or full name given following code:

var list = new list<dictionary<int, string>>(); var type = list.gettype();  console.writeline(type.name); console.writeline(type.fullname); 

based on edited question, want this:

public static string getfriendlyname(this type type) {     if (type == typeof(int))         return "int";     else if (type == typeof(short))         return "short";     else if (type == typeof(byte))         return "byte";     else if (type == typeof(bool))          return "bool";     else if (type == typeof(long))         return "long";     else if (type == typeof(float))         return "float";     else if (type == typeof(double))         return "double";     else if (type == typeof(decimal))         return "decimal";     else if (type == typeof(string))         return "string";     else if (type.isgenerictype)         return type.name.split('`')[0] + "<" + string.join(", ", type.getgenericarguments().select(x => getfriendlyname(x)).toarray()) + ">";     else         return type.name; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -