File tree 3 files changed +26
-2
lines changed
3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
using System . Linq ;
6
6
using System . Text ;
7
+ using CommunityToolkit . Mvvm . SourceGenerators . Extensions ;
7
8
using CommunityToolkit . Mvvm . SourceGenerators . Input . Models ;
8
9
using Microsoft . CodeAnalysis ;
9
10
using Microsoft . CodeAnalysis . CSharp ;
@@ -42,7 +43,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
42
43
. Select ( static ( item , _ ) => item . Length > 0 ) ;
43
44
44
45
// Generate the header file with the attributes
45
- context . RegisterImplementationSourceOutput ( isHeaderFileNeeded , static ( context , item ) =>
46
+ context . RegisterConditionalImplementationSourceOutput ( isHeaderFileNeeded , static context =>
46
47
{
47
48
CompilationUnitSyntax compilationUnit = Execute . GetSyntax ( ) ;
48
49
Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
5
6
using Microsoft . CodeAnalysis ;
6
7
using Microsoft . CodeAnalysis . CSharp ;
7
8
@@ -62,4 +63,25 @@ public static void FilterWithLanguageVersion<T>(
62
63
. Where ( static item => item . IsGeneratorSupported )
63
64
. Select ( static ( item , _ ) => item . Data ) ;
64
65
}
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
+ }
65
87
}
Original file line number Diff line number Diff line change 5
5
using System . Collections . Immutable ;
6
6
using System . Linq ;
7
7
using System . Text ;
8
+ using CommunityToolkit . Mvvm . SourceGenerators . Extensions ;
8
9
using CommunityToolkit . Mvvm . SourceGenerators . Input . Models ;
9
10
using Microsoft . CodeAnalysis ;
10
11
using Microsoft . CodeAnalysis . CSharp ;
@@ -48,7 +49,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
48
49
. Select ( static ( item , _ ) => item . Length > 0 ) ;
49
50
50
51
// Generate the header file with the attributes
51
- context . RegisterImplementationSourceOutput ( isHeaderFileNeeded , static ( context , item ) =>
52
+ context . RegisterConditionalImplementationSourceOutput ( isHeaderFileNeeded , static context =>
52
53
{
53
54
CompilationUnitSyntax compilationUnit = Execute . GetSyntax ( ) ;
54
55
You can’t perform that action at this time.
0 commit comments