32 lines
678 B
C#
32 lines
678 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
|
|
public static class TypeNameCache
|
|
{
|
|
private static Dictionary<Type, string> cache = new Dictionary<Type, string>();
|
|
|
|
private static Regex genericPrefixRegex = new Regex("`\\d+\\[");
|
|
|
|
public static string GetName(Type type)
|
|
{
|
|
if (!cache.TryGetValue(type, out var value))
|
|
{
|
|
value = CalculateName(type);
|
|
cache[type] = value;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
private static string CalculateName(Type type)
|
|
{
|
|
string input = type.ToString();
|
|
input = genericPrefixRegex.Replace(input, "<");
|
|
return input.Replace("]", ">");
|
|
}
|
|
|
|
public static void ClearCache()
|
|
{
|
|
cache.Clear();
|
|
}
|
|
}
|