11using System . Collections . Immutable ;
22using System . Diagnostics ;
33using System . Text . Json ;
4+
45using Microsoft . CodeAnalysis ;
56using Microsoft . CodeAnalysis . CSharp . Syntax ;
67using Microsoft . CodeAnalysis . Diagnostics ;
8+
79using Rocket . Surgery . DependencyInjection . Analyzers . AssemblyProviders ;
810using Rocket . Surgery . DependencyInjection . Analyzers . Descriptors ;
911
@@ -144,15 +146,15 @@ public static IEnumerable<AttributeListSyntax> ToAssemblyAttributes(
144146 yield return Helpers . AddAssemblyAttribute ( ServiceDescriptorTypesKey , GetServiceDescriptorToString ( context , request ) ) ;
145147 }
146148 }
147- #pragma warning disable RS1035
149+ #pragma warning disable RS1035
148150 internal ResolvedSourceLocation ? CacheSourceLocation ( SourceLocation location , IAssemblySymbol assemblySymbol , Func < ResolvedSourceLocation ? > factory )
149151 {
150152 if ( generatedJson . GetSourceLocation ( assemblySymbol , location , factory ) is not { } savedLocation ) return null ;
151153
152154 resultingJson . AddSourceLocation ( assemblySymbol , savedLocation ) ;
153155 return savedLocation ;
154156 }
155- #pragma warning restore RS1035
157+ #pragma warning restore RS1035
156158
157159 private static string CompressString ( byte [ ] bytes ) => Convert . ToBase64String ( bytes ) ;
158160
@@ -199,7 +201,7 @@ private static GetAssemblyConfiguration GetAssemblyCollectionData(AssemblyCollec
199201 return data ;
200202 }
201203
202- #pragma warning disable RS1035
204+ #pragma warning disable RS1035
203205 private void GetAssemblyExpressionData (
204206 IAssemblySymbol assembly ,
205207 out ImmutableList < AssemblyCollection . Item > assemblyItems ,
@@ -222,9 +224,9 @@ ImmutableDictionary<string, IAssemblySymbol> assemblySymbols
222224 if ( generatedJson . GetAssemblyData ( assembly ) is { } generatedData )
223225 {
224226 resultingJson . AddExpressionData ( assembly , generatedData ) ;
225- assemblyItems = generatedData . InternalAssemblyRequests . Select ( z => GetAssembliesFromData ( assemblySymbols , z ) ) . ToImmutableList ( ) ;
226- reflection = generatedData . InternalReflectionRequests . Select ( z => GetReflectionFromData ( compilation , assemblySymbols , z ) ) . ToImmutableList ( ) ;
227- serviceDescriptor = generatedData . InternalServiceDescriptorRequests . Select ( z => GetServiceDescriptorFromData ( compilation , assemblySymbols , z ) ) . ToImmutableList ( ) ;
227+ assemblyItems = [ .. generatedData . InternalAssemblyRequests . Select ( z => GetAssembliesFromData ( assemblySymbols , z ) ) ] ;
228+ reflection = [ .. generatedData . InternalReflectionRequests . Select ( z => GetReflectionFromData ( compilation , assemblySymbols , z ) ) ] ;
229+ serviceDescriptor = [ .. generatedData . InternalServiceDescriptorRequests . Select ( z => GetServiceDescriptorFromData ( compilation , assemblySymbols , z ) ) ] ;
228230 excludeFromResolution = generatedData . ExcludeFromResolution ;
229231 return ;
230232 }
@@ -290,9 +292,9 @@ ImmutableDictionary<string, IAssemblySymbol> assemblySymbols
290292 serviceDescriptor = serviceDescriptorBuilder . ToImmutable ( ) ;
291293
292294 var result = new CompiledAssemblyProviderData (
293- assemblyBuilder . Select ( GetAssemblyCollectionData ) . ToImmutableList ( ) ,
294- reflectionBuilder . Select ( GetReflectionCollectionData ) . ToImmutableList ( ) ,
295- serviceDescriptorBuilder . Select ( z => GetServiceDescriptorCollectionData ( context , z ) ) . ToImmutableList ( ) ,
295+ [ .. assemblyBuilder . Select ( GetAssemblyCollectionData ) ] ,
296+ [ .. reflectionBuilder . Select ( GetReflectionCollectionData ) ] ,
297+ [ .. serviceDescriptorBuilder . Select ( z => GetServiceDescriptorCollectionData ( context , z ) ) ] ,
296298 excludeFromResolution ,
297299 assembly . GetCachedVersion ( )
298300 ) ;
@@ -302,7 +304,7 @@ ImmutableDictionary<string, IAssemblySymbol> assemblySymbols
302304 else
303305 resultingJson . AddExpressionData ( assembly , result ) ;
304306 }
305- #pragma warning restore RS1035
307+ #pragma warning restore RS1035
306308
307309 private static GetReflectionCollectionData GetReflectionCollectionData ( ReflectionCollection . Item item )
308310 {
@@ -441,18 +443,18 @@ ImmutableDictionary<string, IAssemblySymbol> assemblySymbols
441443 foreach ( var item in data . ServiceTypeDescriptors )
442444 {
443445 IServiceTypeDescriptor serviceTypeDescriptor = item switch
444- {
445- { Identifier : 'c' , TypeData : { } typeData } when findType ( assemblySymbols , compilation , typeData . Assembly , typeData . Type ) is { } type =>
446- new CompiledServiceTypeDescriptor ( type ) ,
447- { Identifier : 'c' , TypeData : { } typeData } => new UnknownCompiledServiceTypeDescriptor ( typeData ) ,
448- { Identifier : 'i' , TypeFilter : { } typeFilter } =>
449- new ImplementedInterfacesServiceTypeDescriptor ( LoadTypeFilter ( compilation , typeFilter , source , assemblySymbols ) ) ,
450- { Identifier : 'i' } => new ImplementedInterfacesServiceTypeDescriptor ( null ) ,
451- { Identifier : 'm' } => new MatchingInterfaceServiceTypeDescriptor ( ) ,
452- { Identifier : 's' } => new SelfServiceTypeDescriptor ( ) ,
453- { Identifier : 'a' } => new AsTypeFilterServiceTypeDescriptor ( ) ,
454- _ => throw new ArgumentOutOfRangeException ( nameof ( data ) , data , $ "The type name was { data . GetType ( ) . FullName } ") ,
455- } ;
446+ {
447+ { Identifier : 'c' , TypeData : { } typeData } when findType ( assemblySymbols , compilation , typeData . Assembly , typeData . Type ) is { } type =>
448+ new CompiledServiceTypeDescriptor ( type ) ,
449+ { Identifier : 'c' , TypeData : { } typeData } => new UnknownCompiledServiceTypeDescriptor ( typeData ) ,
450+ { Identifier : 'i' , TypeFilter : { } typeFilter } =>
451+ new ImplementedInterfacesServiceTypeDescriptor ( LoadTypeFilter ( compilation , typeFilter , source , assemblySymbols ) ) ,
452+ { Identifier : 'i' } => new ImplementedInterfacesServiceTypeDescriptor ( null ) ,
453+ { Identifier : 'm' } => new MatchingInterfaceServiceTypeDescriptor ( ) ,
454+ { Identifier : 's' } => new SelfServiceTypeDescriptor ( ) ,
455+ { Identifier : 'a' } => new AsTypeFilterServiceTypeDescriptor ( ) ,
456+ _ => throw new ArgumentOutOfRangeException ( nameof ( data ) , data , $ "The type name was { data . GetType ( ) . FullName } ") ,
457+ } ;
456458 descriptors . Add (
457459 serviceTypeDescriptor
458460 ) ;
@@ -486,16 +488,16 @@ CompiledServiceTypeDescriptors serviceTypeDescriptors
486488 TypeFilter : i is { InterfaceFilter : { } filter } ? LoadTypeFilterData ( filter ) : null
487489 ) ,
488490 MatchingInterfaceServiceTypeDescriptor => new ( 'm' ) ,
489- SelfServiceTypeDescriptor => new ( 's' ) ,
490- AsTypeFilterServiceTypeDescriptor => new ( 'a' ) ,
491+ SelfServiceTypeDescriptor => new ( 's' ) ,
492+ AsTypeFilterServiceTypeDescriptor => new ( 'a' ) ,
491493 CompiledServiceTypeDescriptor { Type : { } namedType } => new ServiceTypeData (
492494 'c' ,
493495 new ( namedType . ContainingAssembly . MetadataName , namedType . MetadataName , namedType . IsUnboundGenericType )
494496 ) ,
495497 _ => throw new ArgumentOutOfRangeException ( nameof ( descriptor ) , descriptor , $ "The type name was { descriptor . GetType ( ) . FullName } ") ,
496498 }
497499 ) ;
498- return new ( serviceDescriptors . ToImmutableArray ( ) , serviceTypeDescriptors . Lifetime ) ;
500+ return new ( [ .. serviceDescriptors ] , serviceTypeDescriptors . Lifetime ) ;
499501 }
500502
501503 private static CompiledTypeFilter LoadTypeFilter (
@@ -597,14 +599,13 @@ ImmutableDictionary<string, IAssemblySymbol> assemblySymbols
597599
598600 private static TypeFilterData LoadTypeFilterData ( CompiledTypeFilter typeFilter ) => new (
599601 typeFilter . ClassFilter ,
600- typeFilter
602+ [ .. typeFilter
601603 . TypeFilterDescriptors
602604 . OfType < NamespaceFilterDescriptor > ( )
603605 . Select ( static z => new NamespaceFilterData ( z . Filter , [ .. z . Namespaces . OrderBy ( z => z ) ] ) )
604606 . OrderBy ( static z => string . Join ( "," , z . Namespaces . OrderBy ( static z => z ) ) )
605607 . ThenBy ( static z => z . Filter )
606- . Select ( static z => z with { Namespaces = [ .. z . Namespaces . OrderBy ( z => z ) ] } )
607- . ToImmutableArray ( ) ,
608+ . Select ( static z => z with { Namespaces = [ .. z . Namespaces . OrderBy ( z => z ) ] } ) ] ,
608609 [
609610 .. typeFilter
610611 . TypeFilterDescriptors . OfType < NameFilterDescriptor > ( )
0 commit comments