有没有一种简单而优雅的方法来获得带有C#泛型类型的字典的类型名称?
目前,我有以下代码工作:
if (property.PropertyType.Name == "Dictionary`2")
{
Type[] arguments = property.PropertyType.GetGenericArguments();
Type keyType = arguments[0];
Type valueType = arguments[1];
properties[property.Name] = $"Dictionary<{keyType.Name},{valueType.Name}>";
}
我想知道有没有更简单的方法来实现我想要的格式化字符串,比如:"Dictionary<type, type>"