Skip to content

Commit 9af5f43

Browse files
Use collection expressions (#79296)
2 parents f2649bb + 5cfde68 commit 9af5f43

File tree

55 files changed

+265
-262
lines changed

Some content is hidden

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

55 files changed

+265
-262
lines changed

src/LanguageServer/ProtocolUnitTests/Commands/ExecuteWorkspaceCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task TestExecuteWorkspaceCommand(bool mutatingLspWorkspace)
3434

3535
var request = new ExecuteCommandParams()
3636
{
37-
Arguments = new object[] { JsonSerializer.Serialize(new TextDocumentIdentifier { DocumentUri = ProtocolConversions.CreateAbsoluteDocumentUri(@"C:\someFile.cs") }) },
37+
Arguments = [JsonSerializer.Serialize(new TextDocumentIdentifier { DocumentUri = ProtocolConversions.CreateAbsoluteDocumentUri(@"C:\someFile.cs") })],
3838
Command = TestWorkspaceCommandHandler.CommandName
3939
};
4040
var response = await server.ExecuteRequestAsync<ExecuteCommandParams, object>(Methods.WorkspaceExecuteCommandName, request, CancellationToken.None);

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/DiagnosticAnalyzerAPIUsageAnalyzer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,22 @@ public override void Initialize(AnalysisContext context)
161161
{
162162
// Change diagnostic analyzer type '{0}' to remove all direct accesses to type(s) '{1}'
163163
rule = DoNotUseTypesFromAssemblyDirectRule;
164-
args = new[]
165-
{
164+
args =
165+
[
166166
declaredType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
167167
string.Join(", ", violatingTypeNamesBuilder)
168-
};
168+
];
169169
}
170170
else
171171
{
172172
// Change diagnostic analyzer type '{0}' to remove all direct and/or indirect accesses to type(s) '{1}', which access type(s) '{2}'
173173
rule = DoNotUseTypesFromAssemblyIndirectRule;
174-
args = new[]
175-
{
174+
args =
175+
[
176176
declaredType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
177177
string.Join(", ", violatingUsedTypeNamesBuilder),
178178
string.Join(", ", violatingTypeNamesBuilder)
179-
};
179+
];
180180
}
181181

182182
Diagnostic diagnostic = declaredType.CreateDiagnostic(rule, args);

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/DiagnosticDescriptorCreationAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ DiagnosticIds.DefineDiagnosticMessageCorrectlyRuleId or
703703
return false;
704704
}
705705

706-
var parts = locationInfo.Split(new[] { AdditionalDocumentLocationInfoSeparator }, StringSplitOptions.None);
706+
var parts = locationInfo.Split([AdditionalDocumentLocationInfoSeparator], StringSplitOptions.None);
707707
if (parts.Length != 3 ||
708708
!int.TryParse(parts[0], out var spanSpart) ||
709709
!int.TryParse(parts[1], out var spanLength))
@@ -982,7 +982,7 @@ private static string FixLineReturns(string s, bool allowMultisentences)
982982
{
983983
Debug.Assert(ContainsLineReturn(s));
984984

985-
var parts = s.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
985+
var parts = s.Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
986986
if (!allowMultisentences)
987987
{
988988
return parts[0];

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/AnalyzerReleaseTrackingFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers
2929
public sealed partial class AnalyzerReleaseTrackingFix() : CodeFixProvider
3030
{
3131
private const string EntryFieldSeparator = "|";
32-
private static readonly string[] s_entryFieldSeparators = new[] { EntryFieldSeparator };
32+
private static readonly string[] s_entryFieldSeparators = [EntryFieldSeparator];
3333

3434
internal const string ShippedAnalyzerReleaseTrackingFileDefaultContent = @"; Shipped analyzer releases
3535
" + CommonAnalyzerReleaseTrackingContent;

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/UnitTests/FixAnalyzers/FixerWithFixAllAnalyzerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private async Task TestCSharpCoreAsync(string source, DiagnosticResult missingGe
9696
await VerifyCS.VerifyAnalyzerAsync(source + fixAllProviderString + sourceSuffix, expected);
9797

9898
// Verify RS1016 (OverrideGetFixAllProviderRule) diagnostic for fixer that does not support FixAllProvider.
99-
expected = new[] { missingGetFixAllProviderOverrideDiagnostic };
99+
expected = [missingGetFixAllProviderOverrideDiagnostic];
100100
await VerifyCS.VerifyAnalyzerAsync(source + sourceSuffix, expected);
101101
}
102102

@@ -480,7 +480,7 @@ End Class
480480
await VerifyVB.VerifyAnalyzerAsync(source + fixAllProviderString + sourceSuffix, expected);
481481

482482
// Verify RS1016 (OverrideGetFixAllProviderRule) diagnostic for fixer that does not support FixAllProvider.
483-
expected = new[] { missingGetFixAllProviderOverrideDiagnostic };
483+
expected = [missingGetFixAllProviderOverrideDiagnostic];
484484
await VerifyVB.VerifyAnalyzerAsync(source + sourceSuffix, expected);
485485
}
486486

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/DiagnosticDescriptorCreationAnalyzerTests.cs

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,10 +1878,10 @@ await VerifyCSharpCodeFixAsync(
18781878
additionalFileName: additionalFileName,
18791879
additionalFileText: string.Format(additionalFileTextFormat, "My Analyzer Title."),
18801880
fixedAdditionalFileText: string.Format(additionalFileTextFormat, "My Analyzer Title"),
1881-
expected: new[]
1882-
{
1881+
expected:
1882+
[
18831883
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
1884-
});
1884+
]);
18851885

18861886
string basicSourceFormat = @"
18871887
Imports System
@@ -1911,10 +1911,10 @@ await VerifyBasicCodeFixAsync(
19111911
additionalFileName: additionalFileName,
19121912
additionalFileText: string.Format(additionalFileTextFormat, "My Analyzer Title."),
19131913
fixedAdditionalFileText: string.Format(additionalFileTextFormat, "My Analyzer Title"),
1914-
expected: new[]
1915-
{
1914+
expected:
1915+
[
19161916
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
1917-
});
1917+
]);
19181918
}
19191919

19201920
[WindowsOnlyFact, WorkItem(3575, "https://github.com/dotnet/roslyn-analyzers/issues/3575")]
@@ -2100,10 +2100,10 @@ await VerifyCSharpCodeFixAsync(
21002100
additionalFileName: additionalFileName,
21012101
additionalFileText: string.Format(additionalFileTextFormat, title),
21022102
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2103-
expected: new[]
2104-
{
2103+
expected:
2104+
[
21052105
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2106-
});
2106+
]);
21072107

21082108
string basicSourceFormat = @"
21092109
Imports System
@@ -2133,10 +2133,10 @@ await VerifyBasicCodeFixAsync(
21332133
additionalFileName: additionalFileName,
21342134
additionalFileText: string.Format(additionalFileTextFormat, title),
21352135
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2136-
expected: new[]
2137-
{
2136+
expected:
2137+
[
21382138
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2139-
});
2139+
]);
21402140
}
21412141
}
21422142

@@ -2302,11 +2302,11 @@ await VerifyCSharpCodeFixAsync(
23022302
additionalFileName: additionalFileName,
23032303
additionalFileText: string.Format(additionalFileTextFormat, "MyDiagnostic. Title."),
23042304
fixedAdditionalFileText: string.Format(additionalFileTextFormat, "MyDiagnostic"),
2305-
expected: new[]
2306-
{
2305+
expected:
2306+
[
23072307
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0),
23082308
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(1)
2309-
});
2309+
]);
23102310

23112311
string basicSourceFormat = @"
23122312
Imports System
@@ -2339,11 +2339,11 @@ await VerifyBasicCodeFixAsync(
23392339
additionalFileName: additionalFileName,
23402340
additionalFileText: string.Format(additionalFileTextFormat, "MyDiagnostic. Title."),
23412341
fixedAdditionalFileText: string.Format(additionalFileTextFormat, "MyDiagnostic"),
2342-
expected: new[]
2343-
{
2342+
expected:
2343+
[
23442344
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0),
23452345
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(1)
2346-
});
2346+
]);
23472347
}
23482348

23492349
[WindowsOnlyFact, WorkItem(3575, "https://github.com/dotnet/roslyn-analyzers/issues/3575")]
@@ -2524,10 +2524,10 @@ await VerifyCSharpCodeFixAsync(
25242524
additionalFileName: additionalFileName,
25252525
additionalFileText: string.Format(additionalFileTextFormat, title),
25262526
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2527-
expected: new[]
2528-
{
2527+
expected:
2528+
[
25292529
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2530-
});
2530+
]);
25312531

25322532
string basicSourceFormat = @"
25332533
Imports System
@@ -2557,10 +2557,10 @@ await VerifyBasicCodeFixAsync(
25572557
additionalFileName: additionalFileName,
25582558
additionalFileText: string.Format(additionalFileTextFormat, title),
25592559
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2560-
expected: new[]
2561-
{
2560+
expected:
2561+
[
25622562
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2563-
});
2563+
]);
25642564
}
25652565
}
25662566

@@ -2686,10 +2686,10 @@ await VerifyCSharpCodeFixAsync(
26862686
additionalFileName: additionalFileName,
26872687
additionalFileText: string.Format(additionalFileTextFormat, title),
26882688
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2689-
expected: new[]
2690-
{
2689+
expected:
2690+
[
26912691
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2692-
});
2692+
]);
26932693

26942694
string basicSourceFormat = @"
26952695
Imports System
@@ -2719,10 +2719,10 @@ await VerifyBasicCodeFixAsync(
27192719
additionalFileName: additionalFileName,
27202720
additionalFileText: string.Format(additionalFileTextFormat, title),
27212721
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedTitle),
2722-
expected: new[]
2723-
{
2722+
expected:
2723+
[
27242724
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticTitleCorrectlyRule).WithLocation(0)
2725-
});
2725+
]);
27262726
}
27272727
}
27282728

@@ -2913,10 +2913,10 @@ await VerifyCSharpCodeFixAsync(
29132913
additionalFileName: additionalFileName,
29142914
additionalFileText: string.Format(additionalFileTextFormat, message),
29152915
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
2916-
expected: new[]
2917-
{
2916+
expected:
2917+
[
29182918
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
2919-
});
2919+
]);
29202920

29212921
string basicSourceFormat = @"
29222922
Imports System
@@ -2946,10 +2946,10 @@ await VerifyBasicCodeFixAsync(
29462946
additionalFileName: additionalFileName,
29472947
additionalFileText: string.Format(additionalFileTextFormat, message),
29482948
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
2949-
expected: new[]
2950-
{
2949+
expected:
2950+
[
29512951
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
2952-
});
2952+
]);
29532953
}
29542954
}
29552955

@@ -3228,10 +3228,10 @@ await VerifyCSharpCodeFixAsync(
32283228
additionalFileName: additionalFileName,
32293229
additionalFileText: string.Format(additionalFileTextFormat, message),
32303230
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
3231-
expected: new[]
3232-
{
3231+
expected:
3232+
[
32333233
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
3234-
});
3234+
]);
32353235

32363236
string basicSourceFormat = @"
32373237
Imports System
@@ -3261,10 +3261,10 @@ await VerifyBasicCodeFixAsync(
32613261
additionalFileName: additionalFileName,
32623262
additionalFileText: string.Format(additionalFileTextFormat, message),
32633263
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
3264-
expected: new[]
3265-
{
3264+
expected:
3265+
[
32663266
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
3267-
});
3267+
]);
32683268
}
32693269
}
32703270

@@ -3410,10 +3410,10 @@ await VerifyCSharpCodeFixAsync(
34103410
additionalFileName: additionalFileName,
34113411
additionalFileText: string.Format(additionalFileTextFormat, message),
34123412
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
3413-
expected: new[]
3414-
{
3413+
expected:
3414+
[
34153415
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
3416-
});
3416+
]);
34173417

34183418
string basicSourceFormat = @"
34193419
Imports System
@@ -3443,10 +3443,10 @@ await VerifyBasicCodeFixAsync(
34433443
additionalFileName: additionalFileName,
34443444
additionalFileText: string.Format(additionalFileTextFormat, message),
34453445
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedMessage),
3446-
expected: new[]
3447-
{
3446+
expected:
3447+
[
34483448
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticMessageCorrectlyRule).WithLocation(0)
3449-
});
3449+
]);
34503450
}
34513451
}
34523452

@@ -3633,10 +3633,10 @@ await VerifyCSharpCodeFixAsync(
36333633
additionalFileName: additionalFileName,
36343634
additionalFileText: string.Format(additionalFileTextFormat, description),
36353635
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedDescription),
3636-
expected: new[]
3637-
{
3636+
expected:
3637+
[
36383638
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticDescriptionCorrectlyRule).WithLocation(0)
3639-
});
3639+
]);
36403640

36413641
string basicSourceFormat = @"
36423642
Imports System
@@ -3666,10 +3666,10 @@ await VerifyBasicCodeFixAsync(
36663666
additionalFileName: additionalFileName,
36673667
additionalFileText: string.Format(additionalFileTextFormat, description),
36683668
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedDescription),
3669-
expected: new[]
3670-
{
3669+
expected:
3670+
[
36713671
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticDescriptionCorrectlyRule).WithLocation(0)
3672-
});
3672+
]);
36733673
}
36743674
}
36753675

@@ -3815,10 +3815,10 @@ await VerifyCSharpCodeFixAsync(
38153815
additionalFileName: additionalFileName,
38163816
additionalFileText: string.Format(additionalFileTextFormat, description),
38173817
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedDescription),
3818-
expected: new[]
3819-
{
3818+
expected:
3819+
[
38203820
VerifyCS.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticDescriptionCorrectlyRule).WithLocation(0)
3821-
});
3821+
]);
38223822

38233823
string basicSourceFormat = @"
38243824
Imports System
@@ -3848,10 +3848,10 @@ await VerifyBasicCodeFixAsync(
38483848
additionalFileName: additionalFileName,
38493849
additionalFileText: string.Format(additionalFileTextFormat, description),
38503850
fixedAdditionalFileText: string.Format(additionalFileTextFormat, fixedDescription),
3851-
expected: new[]
3852-
{
3851+
expected:
3852+
[
38533853
VerifyVB.Diagnostic(DiagnosticDescriptorCreationAnalyzer.DefineDiagnosticDescriptionCorrectlyRule).WithLocation(0)
3854-
});
3854+
]);
38553855
}
38563856
}
38573857

0 commit comments

Comments
 (0)