diff --git a/src/Riok.Mapperly/MapperGenerator.cs b/src/Riok.Mapperly/MapperGenerator.cs index bc20ddcfc3..812e460d40 100644 --- a/src/Riok.Mapperly/MapperGenerator.cs +++ b/src/Riok.Mapperly/MapperGenerator.cs @@ -1,4 +1,5 @@ -using Microsoft.CodeAnalysis; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Riok.Mapperly.Abstractions; using Riok.Mapperly.Configuration; @@ -29,25 +30,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.ReportDiagnostics(compilationDiagnostics); var nestedCompilations = context - .MetadataReferencesProvider.Select( - (metadataReference, _) => - { - if (metadataReference is CompilationReference compilationReference) - { - return compilationReference; - } - - return null; - } - ) - .Where(compilationReference => compilationReference is not null) - .Select((compilationReference, _) => compilationReference!.Compilation) + .MetadataReferencesProvider.Select((metadataReference, _) => (metadataReference as CompilationReference)?.Compilation) .Collect(); // build the compilation context var compilationContext = context .CompilationProvider.Combine(nestedCompilations) - .Select(static (c, _) => new CompilationContext(c.Left, new WellKnownTypes(c.Left), c.Right, new FileNameBuilder())) + .Select( + static (c, _) => + new CompilationContext( + c.Left, + new WellKnownTypes(c.Left), + c.Right.OfType().ToImmutableArray(), + new FileNameBuilder() + ) + ) .WithTrackingName(MapperGeneratorStepNames.BuildCompilationContext); // build the assembly default configurations