Skip to content

Commit 10cf2dd

Browse files
committed
Disabled ValidateAllProperties/RegisterAll generators w/ <= 8.0
1 parent 67ee33f commit 10cf2dd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/ObservableValidatorValidateAllPropertiesGenerator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public void Execute(GeneratorExecutionContext context)
4242
return;
4343
}
4444

45+
// Validate the language version (this needs at least C# 8.0 due to static local functions being used).
46+
// If a lower C# version is set, just skip the execution silently. The fallback path will be used just fine.
47+
if (context.ParseOptions is not CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp8 })
48+
{
49+
return;
50+
}
51+
4552
// Get the symbol for the required attributes
4653
INamedTypeSymbol
4754
validationSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute")!,

Microsoft.Toolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public void Execute(GeneratorExecutionContext context)
3939
return;
4040
}
4141

42+
// Like in the ObservableValidator.ValidateALlProperties generator, execution is skipped if C# >= 8.0 isn't available
43+
if (context.ParseOptions is not CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp8 })
44+
{
45+
return;
46+
}
47+
4248
// Get the symbol for the IRecipient<T> interface type
4349
INamedTypeSymbol iRecipientSymbol = context.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.Messaging.IRecipient`1")!;
4450

0 commit comments

Comments
 (0)