Skip to content

Commit ce1aacd

Browse files
authored
Fix roslyn multi-targeting (#1407)
1 parent e928f82 commit ce1aacd

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Fix analyzer [RCS1019](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1019) ([PR](https://github.com/dotnet/roslynator/pull/1402))
2323
- Fix analyzer [RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250) ([PR](https://github.com/dotnet/roslynator/pull/1403), [PR](https://github.com/dotnet/roslynator/pull/1404))
2424
- Fix code fix for [CS8600](https://josefpihrt.github.io/docs/roslynator/fixes/CS8600) changing the wrong type when casts or `var` are involved ([PR](https://github.com/dotnet/roslynator/pull/1393) by @jroessel)
25+
- Fix Roslyn multi-targeting ([PR](https://github.com/dotnet/roslynator/pull/1407))
2526

2627
## [4.10.0] - 2024-01-24
2728

src/Analyzers.CodeFixes/CSharp/CodeFixes/RawStringLiteralCodeFixProvider.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if ROSLYN_4_2
2-
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
32

43
using System.Collections.Immutable;
54
using System.Composition;
@@ -33,6 +32,7 @@ public override ImmutableArray<string> FixableDiagnosticIds
3332

3433
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3534
{
35+
#if ROSLYN_4_2
3636
SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);
3737

3838
if (!TryFindFirstAncestorOrSelf(root, context.Span, out SyntaxNode node, predicate: f => f.IsKind(SyntaxKind.StringLiteralExpression, SyntaxKind.InterpolatedStringExpression)))
@@ -83,8 +83,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
8383
context.RegisterCodeFix(codeAction, diagnostic);
8484
}
8585
}
86+
#else
87+
await Task.CompletedTask;
88+
#endif
8689
}
8790

91+
#if ROSLYN_4_2
8892
private static Task<Document> RefactorAsync(
8993
Document document,
9094
LiteralExpressionSyntax literalExpression,
@@ -221,5 +225,5 @@ private static Task<Document> UseRawStringLiteralAsync(
221225

222226
return document.WithTextChangeAsync(interpolatedString.Span, sb.ToString(), cancellationToken);
223227
}
224-
}
225228
#endif
229+
}

src/Analyzers/CSharp/Analysis/UnnecessaryRawStringLiteralAnalyzer.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if ROSLYN_4_2
2-
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
32

43
using System.Collections.Immutable;
54
using Microsoft.CodeAnalysis;
@@ -26,10 +25,10 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
2625
}
2726
}
2827

28+
#if ROSLYN_4_2
2929
public override void Initialize(AnalysisContext context)
3030
{
3131
base.Initialize(context);
32-
3332
context.RegisterCompilationStartAction(startContext =>
3433
{
3534
if (((CSharpCompilation)startContext.Compilation).LanguageVersion >= LanguageVersion.CSharp11)
@@ -116,5 +115,5 @@ private static bool ContainsBackSlashOrQuoteOrOpenBrace(string text, int start,
116115

117116
return false;
118117
}
119-
}
120118
#endif
119+
}

src/Analyzers/CSharp/Analysis/UseRawStringLiteralAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if ROSLYN_4_2
2-
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
32

43
using System.Collections.Immutable;
54
using Microsoft.CodeAnalysis;
@@ -26,6 +25,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
2625
}
2726
}
2827

28+
#if ROSLYN_4_2
2929
public override void Initialize(AnalysisContext context)
3030
{
3131
base.Initialize(context);
@@ -89,5 +89,5 @@ private static void AnalyzeInterpolatedStringExpression(SyntaxNodeAnalysisContex
8989
}
9090
}
9191
}
92-
}
9392
#endif
93+
}

src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if ROSLYN_4_0
2-
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
32

43
using System.Collections.Immutable;
54
using Microsoft.CodeAnalysis;
@@ -27,6 +26,7 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
2726
}
2827
}
2928

29+
#if ROSLYN_4_0
3030
public override void Initialize(AnalysisContext context)
3131
{
3232
base.Initialize(context);
@@ -86,5 +86,5 @@ internal static SyntaxNode GetNodeAfterNamespaceDeclaration(FileScopedNamespaceD
8686
? usingDirective
8787
: memberDeclaration;
8888
}
89-
}
9089
#endif
90+
}

0 commit comments

Comments
 (0)