From 56bc078288b03259d319df80d89a6d377d1ea2fb Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Mon, 13 Apr 2026 20:05:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(generator):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将条件判断语句替换为 switch 表达式以提高可读性 - 添加对 partial interface 类型的支持 - 为不支持的类型添加异常处理机制 - 简化代码结构并提升维护性 --- .../AutoRegisterExportedCollectionsGenerator.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs b/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs index 1db4f290..d6fe8db3 100644 --- a/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs +++ b/GFramework.Godot.SourceGenerators/Registration/AutoRegisterExportedCollectionsGenerator.cs @@ -491,11 +491,15 @@ public sealed class AutoRegisterExportedCollectionsGenerator : IIncrementalGener private static string GetTypeDeclarationKeyword(INamedTypeSymbol typeSymbol) { - return typeSymbol.IsRecord - ? typeSymbol.TypeKind == TypeKind.Struct ? "partial record struct" : "partial record" - : typeSymbol.TypeKind == TypeKind.Struct - ? "partial struct" - : "partial class"; + return typeSymbol switch + { + { IsRecord: true, TypeKind: TypeKind.Struct } => "partial record struct", + { IsRecord: true } => "partial record", + { TypeKind: TypeKind.Struct } => "partial struct", + { TypeKind: TypeKind.Class } => "partial class", + { TypeKind: TypeKind.Interface } => "partial interface", + _ => throw new NotSupportedException($"Unsupported type: {typeSymbol.TypeKind}") + }; } private static string GetTypeDeclarationName(INamedTypeSymbol typeSymbol)