diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 64e33d5..8c72367 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -275,7 +275,7 @@ namespace Luban.Job.Common.Defs public TType CreateType(string module, string type) { - type = DefUtil.TrimBracePairs(type, true); + type = DefUtil.TrimBracePairs(type); int sepIndex = DefUtil.IndexOfBaseTypeEnd(type); if (sepIndex > 0) { diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index b17069a..3ba7024 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -136,7 +136,45 @@ namespace Luban.Job.Common.Utils return -1; } - public static string TrimBracePairs(string rawType, bool soft = false) + public static string TrimBracePairs(string rawType) + { + while (rawType.Length > 0 && rawType[0] == '(') + { + int braceDepth = 0; + int level1Left = -1; + int level1Right = -1; + for (int i = 0; i < rawType.Length; i++) + { + if (rawType[i] == '(') + { + braceDepth++; + if (level1Left < 0) + { + level1Left = i; + } + } + if (rawType[i] == ')') + { + braceDepth--; + if (level1Right < 0 && braceDepth == 0) + { + level1Right = i; + break; + } + } + } + if (level1Left >= 0 && level1Right == rawType.Length - 1) + { + rawType = rawType.Substring(1, rawType.Length - 2); + } + else + { + break; + } + } + return rawType; + } + public static string TrimBracePairs2(string rawType, bool soft = false) { while (rawType.Length > 0 && rawType[0] == '(') {