Skip to content

Commit 9625a14

Browse files
Merge pull request #42878 from CyrusNajmabadi/useExprBody
Use expression-bodies for very simple members.
2 parents d99c77a + f6566cb commit 9625a14

File tree

1,768 files changed

+5407
-16201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,768 files changed

+5407
-16201
lines changed

src/Analyzers/CSharp/Analyzers/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionDiagnosticAnalyzer.Analyzer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ private static bool IsDefaultSwitchLabel(SwitchLabelSyntax node)
115115
}
116116

117117
public override SyntaxKind VisitSwitchStatement(SwitchStatementSyntax node)
118-
{
119-
return AnalyzeSwitchStatement(node, out _);
120-
}
118+
=> AnalyzeSwitchStatement(node, out _);
121119

122120
private SyntaxKind AnalyzeSwitchStatement(SwitchStatementSyntax switchStatement, out bool shouldRemoveNextStatement)
123121
{

src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ protected override IndexerDeclarationSyntax WithBody(IndexerDeclarationSyntax de
5454
}
5555

5656
protected override IndexerDeclarationSyntax WithGenerateBody(SemanticModel semanticModel, IndexerDeclarationSyntax declaration)
57-
{
58-
return WithAccessorList(semanticModel, declaration);
59-
}
57+
=> WithAccessorList(semanticModel, declaration);
6058

6159
protected override bool CreateReturnStatementForExpression(SemanticModel semanticModel, IndexerDeclarationSyntax declaration) => true;
6260

src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ protected override PropertyDeclarationSyntax WithBody(PropertyDeclarationSyntax
5454
}
5555

5656
protected override PropertyDeclarationSyntax WithGenerateBody(SemanticModel semanticModel, PropertyDeclarationSyntax declaration)
57-
{
58-
return WithAccessorList(semanticModel, declaration);
59-
}
57+
=> WithAccessorList(semanticModel, declaration);
6058

6159
protected override bool CreateReturnStatementForExpression(SemanticModel semanticModel, PropertyDeclarationSyntax declaration) => true;
6260

src/Analyzers/CSharp/Analyzers/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ protected TDeclaration WithAccessorList(SemanticModel semanticModel, TDeclaratio
295295
}
296296

297297
protected virtual TDeclaration WithAccessorList(TDeclaration declaration, AccessorListSyntax accessorListSyntax)
298-
{
299-
throw new NotImplementedException();
300-
}
298+
=> throw new NotImplementedException();
301299
}
302300
}

src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ private sealed class Rewriter : CSharpSyntaxVisitor<ExpressionSyntax>
2222
private readonly bool _isAllThrowStatements;
2323

2424
private Rewriter(bool isAllThrowStatements)
25-
{
26-
_isAllThrowStatements = isAllThrowStatements;
27-
}
25+
=> _isAllThrowStatements = isAllThrowStatements;
2826

2927
public static StatementSyntax Rewrite(
3028
SwitchStatementSyntax switchStatement,
@@ -145,9 +143,7 @@ private ExpressionSyntax RewriteStatements(SyntaxList<StatementSyntax> statement
145143
}
146144

147145
public override ExpressionSyntax VisitSwitchStatement(SwitchStatementSyntax node)
148-
{
149-
return RewriteSwitchStatement(node);
150-
}
146+
=> RewriteSwitchStatement(node);
151147

152148
private static SwitchLabelSyntax SingleOrDefaultSwitchLabel(SyntaxList<SwitchLabelSyntax> labels)
153149
{
@@ -204,14 +200,10 @@ public override ExpressionSyntax VisitThrowStatement(ThrowStatementSyntax node)
204200
}
205201

206202
public override ExpressionSyntax VisitExpressionStatement(ExpressionStatementSyntax node)
207-
{
208-
return Visit(node.Expression);
209-
}
203+
=> Visit(node.Expression);
210204

211205
public override ExpressionSyntax DefaultVisit(SyntaxNode node)
212-
{
213-
throw ExceptionUtilities.UnexpectedValue(node.Kind());
214-
}
206+
=> throw ExceptionUtilities.UnexpectedValue(node.Kind());
215207
}
216208
}
217209
}

src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ internal partial class UseExpressionBodyCodeFixProvider : SyntaxEditorBasedCodeF
3232
[ImportingConstructor]
3333
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
3434
public UseExpressionBodyCodeFixProvider()
35-
{
36-
FixableDiagnosticIds = _helpers.SelectAsArray(h => h.DiagnosticId);
37-
}
35+
=> FixableDiagnosticIds = _helpers.SelectAsArray(h => h.DiagnosticId);
3836

3937
protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic)
4038
=> !diagnostic.IsSuppressed ||

src/Analyzers/CSharp/Tests/QualifyMemberAccess/QualifyMemberAccessTests.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,13 @@ internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProvider
2121
=> (new CSharpQualifyMemberAccessDiagnosticAnalyzer(), new CSharpQualifyMemberAccessCodeFixProvider());
2222

2323
private Task TestAsyncWithOption(string code, string expected, PerLanguageOption2<CodeStyleOption2<bool>> option)
24-
{
25-
return TestAsyncWithOptionAndNotificationOption(code, expected, option, NotificationOption2.Error);
26-
}
24+
=> TestAsyncWithOptionAndNotificationOption(code, expected, option, NotificationOption2.Error);
2725

2826
private Task TestAsyncWithOptionAndNotificationOption(string code, string expected, PerLanguageOption2<CodeStyleOption2<bool>> option, NotificationOption2 notification)
29-
{
30-
return TestInRegularAndScriptAsync(code, expected, options: Option(option, true, notification));
31-
}
27+
=> TestInRegularAndScriptAsync(code, expected, options: Option(option, true, notification));
3228

3329
private Task TestMissingAsyncWithOption(string code, PerLanguageOption2<CodeStyleOption2<bool>> option)
34-
{
35-
return TestMissingAsyncWithOptionAndNotificationOption(code, option, NotificationOption2.Error);
36-
}
30+
=> TestMissingAsyncWithOptionAndNotificationOption(code, option, NotificationOption2.Error);
3731

3832
private Task TestMissingAsyncWithOptionAndNotificationOption(string code, PerLanguageOption2<CodeStyleOption2<bool>> option, NotificationOption2 notification)
3933
=> TestMissingInRegularAndScriptAsync(code, new TestParameters(options: Option(option, true, notification)));

src/Analyzers/CSharp/Tests/UsePatternMatching/CSharpAsAndNullCheckTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public async Task InlineTypeCheck1(string input, string output)
5050
[InlineData("(x = o as string) == null", "!(o is string x)")]
5151
[InlineData("null == (x = o as string)", "!(o is string x)")]
5252
public async Task InlineTypeCheck2(string input, string output)
53-
{
54-
await TestStatement($"while ({input}) {{ }}", $"while ({output}) {{ }}");
55-
}
53+
=> await TestStatement($"while ({input}) {{ }}", $"while ({output}) {{ }}");
5654

5755
private async Task TestStatement(string input, string output)
5856
{

src/Analyzers/Core/Analyzers/AbstractBuiltInCodeStyleDiagnosticAnalyzer.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,10 @@ private static void AddDiagnosticIdToOptionMapping(string diagnosticId, ILanguag
200200
}
201201

202202
private static void AddDiagnosticIdToOptionMapping(string diagnosticId, ImmutableHashSet<IPerLanguageOption> options)
203-
{
204-
IDEDiagnosticIdToOptionMappingHelper.AddOptionMapping(diagnosticId, options);
205-
}
203+
=> IDEDiagnosticIdToOptionMappingHelper.AddOptionMapping(diagnosticId, options);
206204

207205
private static void AddDiagnosticIdToOptionMapping(string diagnosticId, ImmutableHashSet<ILanguageSpecificOption> options, string language)
208-
{
209-
IDEDiagnosticIdToOptionMappingHelper.AddOptionMapping(diagnosticId, options, language);
210-
}
206+
=> IDEDiagnosticIdToOptionMappingHelper.AddOptionMapping(diagnosticId, options, language);
211207

212208
public abstract DiagnosticAnalyzerCategory GetAnalyzerCategory();
213209

src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ public sealed class LocalizableStringWithArguments : LocalizableString, IObjectW
162162
private readonly string[] _formatArguments;
163163

164164
static LocalizableStringWithArguments()
165-
{
166-
ObjectBinder.RegisterTypeReader(typeof(LocalizableStringWithArguments), reader => new LocalizableStringWithArguments(reader));
167-
}
165+
=> ObjectBinder.RegisterTypeReader(typeof(LocalizableStringWithArguments), reader => new LocalizableStringWithArguments(reader));
168166

169167
public LocalizableStringWithArguments(LocalizableString messageFormat, params object[] formatArguments)
170168
{

0 commit comments

Comments
 (0)