-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathDocUtilities.cs
More file actions
45 lines (40 loc) · 1.35 KB
/
DocUtilities.cs
File metadata and controls
45 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace MudExtensions.Docs
{
public static class DocUtilities
{
public static string GetFriendlyTypeName(Type type)
{
if (type.IsGenericType)
{
var genericTypeName = type.GetGenericTypeDefinition().Name;
var backtickIndex = genericTypeName.IndexOf('`');
if (backtickIndex > 0)
genericTypeName = genericTypeName.Substring(0, backtickIndex);
var genericArgs = type.GetGenericArguments()
.Select(GetFriendlyTypeName)
.ToArray();
return $"{genericTypeName}<{string.Join(", ", genericArgs)}>";
}
if (type.IsArray)
{
return $"{GetFriendlyTypeName(type.GetElementType()!)}[]";
}
return type.Name switch
{
"String" => "string",
"Int32" => "int",
"Boolean" => "bool",
"Object" => "object",
"Void" => "void",
"Decimal" => "decimal",
"Double" => "double",
"Single" => "float",
"Int64" => "long",
"Int16" => "short",
"Byte" => "byte",
_ => type.Name
};
}
}
}