Is there an easy way without writing a recursive method which will give a \'user friendly\' name for a generic type from the Type class?
E.g. For the fo
You can avoid writing a recursive method by calling the recursive method that's already provided for you:
static string GetTypeName(Type type)
{
var codeDomProvider = CodeDomProvider.CreateProvider("C#");
var typeReferenceExpression = new CodeTypeReferenceExpression(new CodeTypeReference(type));
using (var writer = new StringWriter())
{
codeDomProvider.GenerateCodeFromExpression(typeReferenceExpression, writer, new CodeGeneratorOptions());
return writer.GetStringBuilder().ToString();
}
}
Note that this includes the type namespaces, but excludes the assembly references. For the type in your question, the result looks like this:
System.Collections.Generic.List>
It isn't clear to me whether that qualifies as "something like" List.