Skip to content

Commit bdd4567

Browse files
committed
Use Roslyn API for C# language-version check
Use the Roslyn 5+ API when available to determine the C# language version. Add a conditional compilation branch that calls Compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp14) when ROSLYN_5_0_0_OR_GREATER is defined, and fall back to the previous IsLanguageVersionPreview() check otherwise. This avoids generating invalid code on older Roslyn builds while correctly detecting C#14+ in newer toolchains.
1 parent e7a54bd commit bdd4567

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/CommunityToolkit.Mvvm.CodeFixers/UsePartialPropertyForObservablePropertyCodeFixer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
8282
SemanticModel semanticModel = (await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false))!;
8383

8484
// If the language is not preview, we cannot apply this code fix (as it would generate invalid C# code)
85+
#if ROSLYN_5_0_0_OR_GREATER
86+
if (!semanticModel.Compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp14))
87+
#else
8588
if (!semanticModel.Compilation.IsLanguageVersionPreview())
89+
#endif
8690
{
8791
return;
8892
}

0 commit comments

Comments
 (0)