mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-06 16:16:44 +08:00
refactor(generator): 优化类型声明关键字生成逻辑
- 将条件判断语句替换为 switch 表达式以提高可读性 - 添加对 partial interface 类型的支持 - 为不支持的类型添加异常处理机制 - 简化代码结构并提升维护性
This commit is contained in:
parent
eeef5961d7
commit
56bc078288
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user