fix: Improved Type GetSyntaxName method

This commit is contained in:
Chris Cameron
2018-09-27 15:07:21 -04:00
parent 588badbf58
commit c3d73e1091

View File

@@ -317,30 +317,14 @@ namespace ICD.Common.Utils.Extensions
if (extends == null) if (extends == null)
throw new ArgumentNullException("extends"); throw new ArgumentNullException("extends");
// Nullable
Type nullableType = Nullable.GetUnderlyingType(extends); Type nullableType = Nullable.GetUnderlyingType(extends);
if (nullableType != null) if (nullableType != null)
return nullableType.GetSyntaxName() + "?"; return nullableType.GetSyntaxName() + "?";
if (!(extends.IsGenericType && extends.Name.Contains('`'))) // Generic
if (extends.IsGenericType)
{ {
switch (extends.Name)
{
case "String":
return "string";
case "Int32":
return "int";
case "Decimal":
return "decimal";
case "Object":
return "object";
case "Void":
return "void";
default:
return string.IsNullOrEmpty(extends.FullName) ? extends.Name : extends.FullName;
}
}
StringBuilder sb = new StringBuilder(extends.Name.Substring(0, extends.Name.IndexOf('`'))); StringBuilder sb = new StringBuilder(extends.Name.Substring(0, extends.Name.IndexOf('`')));
sb.Append('<'); sb.Append('<');
@@ -357,5 +341,24 @@ namespace ICD.Common.Utils.Extensions
return sb.ToString(); return sb.ToString();
} }
// Default
switch (extends.Name)
{
case "String":
return "string";
case "Int32":
return "int";
case "Decimal":
return "decimal";
case "Object":
return "object";
case "Void":
return "void";
default:
return extends.Name;
}
}
} }
} }