Skip to content

Commit

Permalink
Improve the array handling of ParseGenericArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Nov 13, 2024
1 parent 3a34032 commit d7d79e7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CSharpRepl/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ public static string ParseGenericArgs(this Type type)
return returnTypeName.Replace($"`{args.Length}", $"<{string.Join(", ", returnArgs)}>");
}

[GeneratedRegex(@"\[,*\]")]
private static partial Regex ArrayRegex { get; }

private static string GetPrimitiveTypeName(Type type)
{
var typeName = type.Name;
if (type.IsArray)
{
typeName = ArrayRegex.Replace(typeName, "");
typeName = ParseGenericArgs(type.GetElementType()!);
}

var returnValue = typeName switch
Expand All @@ -47,6 +44,9 @@ private static string GetPrimitiveTypeName(Type type)
"UInt16" => "ushort",
"UInt32" => "uint",
"UInt64" => "ulong",
"Object" => "object",
"IntPtr" => "nint",
"UIntPtr" => "nuint",
_ => typeName
};

Expand Down

0 comments on commit d7d79e7

Please sign in to comment.