From d72d4ab0bd2236fd944a62d5914fb2c2da58bab8 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 28 Mar 2026 19:32:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(GFramework.SourceGenerators):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96ContextGetGenerator=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E9=9B=86=E5=90=88=E7=B1=BB=E5=9E=8B=E9=81=8D=E5=8E=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构了EnumerateCollectionTypeCandidates方法的调用方式 - 使用模式匹配简化了类型参数的提取逻辑 - 移除了不必要的SelectMany操作提高代码可读性 - 添加了空值检查增强代码健壮性 - 在方法末尾添加了必要的换行符保持代码格式一致 --- GFramework.SourceGenerators/Rule/ContextGetGenerator.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GFramework.SourceGenerators/Rule/ContextGetGenerator.cs b/GFramework.SourceGenerators/Rule/ContextGetGenerator.cs index 6e11580..9248f81 100644 --- a/GFramework.SourceGenerators/Rule/ContextGetGenerator.cs +++ b/GFramework.SourceGenerators/Rule/ContextGetGenerator.cs @@ -711,11 +711,11 @@ public sealed class ContextGetGenerator : IIncrementalGenerator if (readOnlyList is null || fieldType is not INamedTypeSymbol targetType) return false; - var allTypeCandidates = EnumerateCollectionTypeCandidates(targetType) - .SelectMany(candidateType => candidateType.TypeArguments); - - foreach (var candidateElementType in allTypeCandidates) + foreach (var candidateType in EnumerateCollectionTypeCandidates(targetType)) { + if (candidateType is not { TypeArguments: [var candidateElementType] }) + continue; + var expectedSourceType = readOnlyList.Construct(candidateElementType); if (!expectedSourceType.IsAssignableTo(targetType)) continue; @@ -727,6 +727,7 @@ public sealed class ContextGetGenerator : IIncrementalGenerator return false; } + private static IEnumerable EnumerateCollectionTypeCandidates(INamedTypeSymbol typeSymbol) { yield return typeSymbol;