refactor(GFramework.SourceGenerators): 优化集合类型候选枚举逻辑

- 将嵌套循环重构为使用 SelectMany 扁平化集合类型参数
- 简化了候选元素类型的遍历逻辑
- 提高了代码可读性和性能
- 移除了不必要的 continue 语句
- 保持了原有的类型匹配功能不变
This commit is contained in:
GeWuYou 2026-03-28 19:40:02 +08:00
parent d72d4ab0bd
commit 4fb1da2da6

View File

@ -711,11 +711,11 @@ public sealed class ContextGetGenerator : IIncrementalGenerator
if (readOnlyList is null || fieldType is not INamedTypeSymbol targetType)
return false;
foreach (var candidateType in EnumerateCollectionTypeCandidates(targetType))
{
if (candidateType is not { TypeArguments: [var candidateElementType] })
continue;
var allTypeCandidates = EnumerateCollectionTypeCandidates(targetType)
.SelectMany(candidateType => candidateType.TypeArguments);
foreach (var candidateElementType in allTypeCandidates)
{
var expectedSourceType = readOnlyList.Construct(candidateElementType);
if (!expectedSourceType.IsAssignableTo(targetType))
continue;
@ -724,10 +724,10 @@ public sealed class ContextGetGenerator : IIncrementalGenerator
return true;
}
return false;
}
private static IEnumerable<INamedTypeSymbol> EnumerateCollectionTypeCandidates(INamedTypeSymbol typeSymbol)
{
yield return typeSymbol;