mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
fix: Improved Type GetSyntaxName method
This commit is contained in:
@@ -317,45 +317,48 @@ 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)
|
StringBuilder sb = new StringBuilder(extends.Name.Substring(0, extends.Name.IndexOf('`')));
|
||||||
|
sb.Append('<');
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
foreach (Type t in extends.GetGenericArguments())
|
||||||
{
|
{
|
||||||
case "String":
|
if (!first)
|
||||||
return "string";
|
sb.Append(',');
|
||||||
case "Int32":
|
sb.Append(t.GetSyntaxName());
|
||||||
return "int";
|
first = false;
|
||||||
case "Decimal":
|
|
||||||
return "decimal";
|
|
||||||
case "Object":
|
|
||||||
return "object";
|
|
||||||
case "Void":
|
|
||||||
return "void";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return string.IsNullOrEmpty(extends.FullName) ? extends.Name : extends.FullName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.Append('>');
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(extends.Name.Substring(0, extends.Name.IndexOf('`')));
|
// Default
|
||||||
sb.Append('<');
|
switch (extends.Name)
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
foreach (Type t in extends.GetGenericArguments())
|
|
||||||
{
|
{
|
||||||
if (!first)
|
case "String":
|
||||||
sb.Append(',');
|
return "string";
|
||||||
sb.Append(t.GetSyntaxName());
|
case "Int32":
|
||||||
first = false;
|
return "int";
|
||||||
|
case "Decimal":
|
||||||
|
return "decimal";
|
||||||
|
case "Object":
|
||||||
|
return "object";
|
||||||
|
case "Void":
|
||||||
|
return "void";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return extends.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append('>');
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user