From 32f0038e343a20a750f068f0121021d6d9a1ea02 Mon Sep 17 00:00:00 2001
From: ninemine <1371605831@qq.com>
Date: Mon, 15 Dec 2025 11:36:06 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B1=BB=E5=9E=8B=E5=8F=8B?=
=?UTF-8?q?=E5=A5=BD=E7=9A=84=E5=90=8D=E7=A7=B0=E6=89=93=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Convention/[Runtime]/Config.cs | 70 ++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/Convention/[Runtime]/Config.cs b/Convention/[Runtime]/Config.cs
index 61cf656..115f0d9 100644
--- a/Convention/[Runtime]/Config.cs
+++ b/Convention/[Runtime]/Config.cs
@@ -2904,4 +2904,74 @@ namespace Convention
#endregion
}
+
+ public static partial class Utility
+ {
+ ///
+ /// 获取类型的友好显示名称,支持泛型、数组等复杂类型
+ ///
+ public static string GetFriendlyName(this Type type)
+ {
+ if (type == null) return null;
+
+ // 处理泛型类型
+ if (type.IsGenericType)
+ {
+ // 特殊处理可空类型(Nullable)
+ if (type.IsNullable())
+ {
+ return $"{GetFriendlyName(type.GetGenericArguments()[0])}?";
+ }
+
+ var sb = new StringBuilder();
+ // 获取类型基础名称(移除 `1, `2 等后缀)
+ string baseName = type.Name.Contains('`') ? type.Name[..type.Name.IndexOf('`')] : type.Name;
+ sb.Append(baseName);
+ sb.Append('<');
+
+ // 递归处理泛型参数
+ Type[] args = type.GetGenericArguments();
+ for (int i = 0; i < args.Length; i++)
+ {
+ if (i > 0) sb.Append(", ");
+ sb.Append(GetFriendlyName(args[i]));
+ }
+
+ sb.Append('>');
+ return sb.ToString();
+ }
+
+ // 处理数组类型
+ if (type.IsArray)
+ {
+ string elementName = GetFriendlyName(type.GetElementType());
+ int rank = type.GetArrayRank();
+ return rank == 1 ? $"{elementName}[]" : $"{elementName}[{new string(',', rank - 1)}]";
+ }
+
+ // 处理指针类型
+ if (type.IsPointer)
+ {
+ return $"{GetFriendlyName(type.GetElementType())}*";
+ }
+
+ // 处理引用类型(ref/out 参数)
+ if (type.IsByRef)
+ {
+ return $"{GetFriendlyName(type.GetElementType())}&";
+ }
+
+ // 普通类型直接返回名称
+ return type.Name;
+ }
+
+ ///
+ /// 判断是否为可空类型
+ ///
+ public static bool IsNullable(this Type type)
+ {
+ return type.IsGenericType &&
+ type.GetGenericTypeDefinition() == typeof(Nullable<>);
+ }
+ }
}
\ No newline at end of file