@@ -15,8 +15,12 @@ public sealed partial class ImmediateHandlersGenerator : IIncrementalGenerator
1515{
1616 public void Initialize ( IncrementalGeneratorInitializationContext context )
1717 {
18- var assemblyName = context . CompilationProvider
19- . Select ( ( cp , _ ) => cp . GetAssemblyIdentifier ( ) )
18+ var assemblyDefaults = context . CompilationProvider
19+ . Select ( ( cp , _ ) => new AssemblyDefaults
20+ {
21+ AssemblyName = cp . GetAssemblyIdentifier ( ) ,
22+ LanguageVersion = ( cp . SyntaxTrees . FirstOrDefault ( ) ? . Options as CSharpParseOptions ) ? . LanguageVersion ?? LanguageVersion . CSharp12 ,
23+ } )
2024 . WithTrackingName ( "AssemblyName" ) ;
2125
2226 var @namespace = context
@@ -44,6 +48,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4448 predicate : ( node , _ ) => node is TypeDeclarationSyntax ,
4549 TransformHandler . ParseHandler
4650 )
51+ . WhereNotNull ( )
52+ . Where ( h => h . DisplayName is { } && ! ( h . OverrideBehaviors ? . Any ( b => b is null ) ?? false ) )
4753 . WithTrackingName ( "Handlers" ) ;
4854
4955 var handlerNodes = handlers
@@ -62,11 +68,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
6268 ) ;
6369
6470 var registrationNodes = handlers
65- . Select ( ( h , _ ) => ( h ? . DisplayName , h ? . ServiceLifetime , h ? . OverrideBehaviors ) )
6671 . Collect ( )
6772 . Combine ( behaviors )
6873 . Combine ( @namespace
69- . Combine ( assemblyName )
74+ . Combine ( assemblyDefaults )
7075 )
7176 . WithTrackingName ( "Registrations" ) ;
7277
@@ -77,28 +82,22 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
7782 handlers : node . Left . Left ,
7883 behaviors : node . Left . Right ,
7984 @namespace : node . Right . Left ,
80- assemblyName : node . Right . Right
85+ assemblyDefaults : node . Right . Right
8186 )
8287 ) ;
8388 }
8489
8590 private static void RenderServiceCollectionExtension (
8691 SourceProductionContext context ,
87- ImmutableArray < ( string ? DisplayName , string ? ServiceLifetime , EquatableReadOnlyList < Behavior ? > ? Behaviors ) > handlers ,
92+ ImmutableArray < Handler > handlers ,
8893 ImmutableArray < Behavior ? > behaviors ,
8994 string ? @namespace ,
90- string assemblyName
95+ AssemblyDefaults assemblyDefaults
9196 )
9297 {
9398 var cancellationToken = context . CancellationToken ;
9499 cancellationToken . ThrowIfCancellationRequested ( ) ;
95100
96- if ( ! handlers . Any ( ) )
97- return ;
98-
99- if ( handlers . Any ( h => h . DisplayName is null || ( h . Behaviors ? . Any ( b => b is null ) ?? false ) ) )
100- return ;
101-
102101 if ( behaviors . Any ( b => b is null ) )
103102 return ;
104103
@@ -112,16 +111,22 @@ string assemblyName
112111 so . Import (
113112 new
114113 {
114+ assemblyDefaults . AssemblyName ,
115+ assemblyDefaults . LanguageVersion ,
115116 Namespace = @namespace ,
116- AssemblyName = assemblyName ,
117- Handlers = handlers . Select ( x => new { x . DisplayName , x . ServiceLifetime } ) ,
117+ Version = ThisAssembly . InformationalVersion ,
118+
118119 Behaviors = behaviors
119- . Concat ( handlers . SelectMany ( h => h . Behaviors ?? [ ] ) )
120+ . Concat ( handlers . SelectMany ( h => h . OverrideBehaviors ?? [ ] ) )
120121 . WhereNotNull ( )
121122 . Select ( b => new { b . RegistrationType } )
122123 . Distinct ( ) ,
123124
124- Version = ThisAssembly . InformationalVersion ,
125+ HandlersByTag = handlers
126+ . GroupBy (
127+ h => h . Tags ,
128+ StringComparer . Ordinal
129+ ) ,
125130 }
126131 ) ;
127132
@@ -140,17 +145,14 @@ string assemblyName
140145
141146 private static void RenderHandler (
142147 SourceProductionContext context ,
143- Handler ? handler ,
148+ Handler handler ,
144149 ImmutableArray < Behavior ? > behaviors ,
145150 Template template
146151 )
147152 {
148153 var cancellationToken = context . CancellationToken ;
149154 cancellationToken . ThrowIfCancellationRequested ( ) ;
150155
151- if ( handler == null )
152- return ;
153-
154156 var responseType = handler . ResponseType ?? new ( )
155157 {
156158 Name = "global::System.ValueTuple" ,
@@ -204,10 +206,11 @@ Template template
204206 private static List < Behavior ? > BuildPipeline (
205207 GenericType requestType ,
206208 GenericType responseType ,
207- IEnumerable < Behavior ? > enumerable ) =>
208- [
209- .. enumerable . Where ( b => b . IsValid ( requestType , responseType ) ) ,
210- ] ;
209+ IEnumerable < Behavior ? > enumerable
210+ ) =>
211+ [
212+ .. enumerable . Where ( b => b . IsValid ( requestType , responseType ) ) ,
213+ ] ;
211214
212215 private sealed record RenderBehavior
213216 {
0 commit comments