Skip to content

Commit 67ee33f

Browse files
committed
Removed unnecessary C# version checks in two generators
1 parent fef65a5 commit 67ee33f

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

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

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

45-
// Validate the language version
46-
if (context.ParseOptions is not CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp9 })
47-
{
48-
context.ReportDiagnostic(Diagnostic.Create(UnsupportedCSharpLanguageVersionError, null));
49-
}
50-
5145
// Get the symbol for the required attributes
5246
INamedTypeSymbol
5347
validationSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute")!,

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

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

42-
// Validate the language version
43-
if (context.ParseOptions is not CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp9 })
44-
{
45-
context.ReportDiagnostic(Diagnostic.Create(UnsupportedCSharpLanguageVersionError, null));
46-
}
47-
4842
// Get the symbol for the IRecipient<T> interface type
4943
INamedTypeSymbol iRecipientSymbol = context.Compilation.GetTypeByMetadataName("Microsoft.Toolkit.Mvvm.Messaging.IRecipient`1")!;
5044

UnitTests/UnitTests.SourceGenerators/Test_SourceGeneratorsDiagnostics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ public partial class SampleViewModel : ObservableValidator
319319
}
320320
}";
321321

322+
// This is explicitly allowed in C# < 9.0, as it doesn't use any new features
322323
VerifyGeneratedDiagnostics<ObservableValidatorValidateAllPropertiesGenerator>(
323-
CSharpSyntaxTree.ParseText(source, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_3)),
324-
"MVVMTK0013");
324+
CSharpSyntaxTree.ParseText(source, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_3)));
325325
}
326326

327327
[TestCategory("Mvvm")]
@@ -368,9 +368,9 @@ public void Receive(MyMessage message)
368368
}
369369
}";
370370

371+
// This is explicitly allowed in C# < 9.0, as it doesn't use any new features
371372
VerifyGeneratedDiagnostics<IMessengerRegisterAllGenerator>(
372-
CSharpSyntaxTree.ParseText(source, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_3)),
373-
"MVVMTK0013");
373+
CSharpSyntaxTree.ParseText(source, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_3)));
374374
}
375375

376376
/// <summary>

0 commit comments

Comments
 (0)