Skip to content

Commit 31e712f

Browse files
committed
Fix ObservableValidatorValidateAllPropertiesGenerator and IMessengerRegisterAllGenerator to provide a nicer "unsupported C# language version" diagnostic instead of simply generating unsupported code and failing later in compilation
1 parent a47ce3b commit 31e712f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservableValidatorValidateAllPropertiesGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
12+
using static CommunityToolkit.Mvvm.SourceGenerators.Diagnostics.DiagnosticDescriptors;
1213

1314
namespace CommunityToolkit.Mvvm.SourceGenerators;
1415

@@ -39,6 +40,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3940
.Select(static (item, _) => Execute.GetInfo(item))
4041
.WithComparer(ValidationInfo.Comparer.Default);
4142

43+
context.FilterWithLanguageVersion(ref validationInfo, LanguageVersion.CSharp8, UnsupportedCSharpLanguageVersionError);
44+
4245
// Check whether the header file is needed
4346
IncrementalValueProvider<bool> isHeaderFileNeeded =
4447
validationInfo

CommunityToolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.CodeAnalysis;
1111
using Microsoft.CodeAnalysis.CSharp;
1212
using Microsoft.CodeAnalysis.CSharp.Syntax;
13+
using static CommunityToolkit.Mvvm.SourceGenerators.Diagnostics.DiagnosticDescriptors;
1314

1415
namespace CommunityToolkit.Mvvm.SourceGenerators;
1516

@@ -47,6 +48,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
4748
.Select(static (item, _) => Execute.GetInfo(item.Type, item.Interfaces))
4849
.WithComparer(RecipientInfo.Comparer.Default);
4950

51+
context.FilterWithLanguageVersion(ref recipientInfo, LanguageVersion.CSharp8, UnsupportedCSharpLanguageVersionError);
52+
5053
// Check whether the header file is needed
5154
IncrementalValueProvider<bool> isHeaderFileNeeded =
5255
recipientInfo

0 commit comments

Comments
 (0)