File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 44
55using  System . Linq ; 
66using  System . Text ; 
7+ using  CommunityToolkit . Mvvm . SourceGenerators . Extensions ; 
78using  CommunityToolkit . Mvvm . SourceGenerators . Input . Models ; 
89using  Microsoft . CodeAnalysis ; 
910using  Microsoft . CodeAnalysis . CSharp ; 
@@ -42,7 +43,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4243            . Select ( static  ( item ,  _ )  =>  item . Length  >  0 ) ; 
4344
4445        // Generate the header file with the attributes 
45-         context . RegisterImplementationSourceOutput ( isHeaderFileNeeded ,  static  ( context ,   item )  => 
46+         context . RegisterConditionalImplementationSourceOutput ( isHeaderFileNeeded ,  static  context => 
4647        { 
4748            CompilationUnitSyntax  compilationUnit  =  Execute . GetSyntax ( ) ; 
4849
Original file line number Diff line number Diff line change 22// The .NET Foundation licenses this file to you under the MIT license. 
33// See the LICENSE file in the project root for more information. 
44
5+ using  System ; 
56using  Microsoft . CodeAnalysis ; 
67using  Microsoft . CodeAnalysis . CSharp ; 
78
@@ -62,4 +63,25 @@ public static void FilterWithLanguageVersion<T>(
6263            . Where ( static  item =>  item . IsGeneratorSupported ) 
6364            . Select ( static  ( item ,  _ )  =>  item . Data ) ; 
6465    } 
66+ 
67+     /// <summary> 
68+     /// Conditionally invokes <see cref="IncrementalGeneratorInitializationContext.RegisterImplementationSourceOutput{TSource}(IncrementalValueProvider{TSource}, System.Action{SourceProductionContext, TSource})"/> 
69+     /// if the value produced by the input <see cref="IncrementalValueProvider{TValue}"/> is <see langword="true"/>. 
70+     /// </summary> 
71+     /// <param name="context">The input <see cref="IncrementalGeneratorInitializationContext"/> value being used.</param> 
72+     /// <param name="source">The source <see cref="IncrementalValueProvider{TValues}"/> instance.</param> 
73+     /// <param name="action">The conditional <see cref="Action{T}"/> to invoke.</param> 
74+     public  static   void  RegisterConditionalImplementationSourceOutput ( 
75+         this  IncrementalGeneratorInitializationContext  context , 
76+         IncrementalValueProvider < bool >  source , 
77+         Action < SourceProductionContext >  action ) 
78+     { 
79+         context . RegisterImplementationSourceOutput ( source ,  ( context ,  flag )  => 
80+         { 
81+             if  ( flag ) 
82+             { 
83+                 action ( context ) ; 
84+             } 
85+         } ) ; 
86+     } 
6587} 
Original file line number Diff line number Diff line change 55using  System . Collections . Immutable ; 
66using  System . Linq ; 
77using  System . Text ; 
8+ using  CommunityToolkit . Mvvm . SourceGenerators . Extensions ; 
89using  CommunityToolkit . Mvvm . SourceGenerators . Input . Models ; 
910using  Microsoft . CodeAnalysis ; 
1011using  Microsoft . CodeAnalysis . CSharp ; 
@@ -48,7 +49,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4849            . Select ( static  ( item ,  _ )  =>  item . Length  >  0 ) ; 
4950
5051        // Generate the header file with the attributes 
51-         context . RegisterImplementationSourceOutput ( isHeaderFileNeeded ,  static  ( context ,   item )  => 
52+         context . RegisterConditionalImplementationSourceOutput ( isHeaderFileNeeded ,  static  context => 
5253        { 
5354            CompilationUnitSyntax  compilationUnit  =  Execute . GetSyntax ( ) ; 
5455
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments