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;