Skip to content

Commit 2728f2c

Browse files
kasperk81sbomeragocke
authored
use collection syntax in illink (#108458)
Co-authored-by: Sven Boemer <[email protected]> Co-authored-by: Andy Gocke <[email protected]>
1 parent fd9c728 commit 2728f2c

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

src/tools/illink/external/Mono.Options/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ protected Option (string prototype, string description, int maxValueCount, bool
440440
this.names = (this is OptionSet.Category)
441441
// append GetHashCode() so that "duplicate" categories have distinct
442442
// names, e.g. adding multiple "" categories should be valid.
443-
? new[]{prototype + this.GetHashCode ()}
443+
? [prototype + this.GetHashCode ()]
444444
: prototype.Split ('|');
445445

446446
if (this is OptionSet.Category || this is CommandOption)

src/tools/illink/src/ILLink.CodeFix/DynamicallyAccessedMembersCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ private static async Task<Document> AddAttributeAsync (
132132

133133
var editor = await DocumentEditor.CreateAsync (document, cancellationToken).ConfigureAwait (false);
134134
var generator = editor.Generator;
135-
var attributeArguments = new[] { generator.AttributeArgument (generator.MemberAccessExpression (generator.DottedName ("System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes"), stringArguments)) };
135+
SyntaxNode[] attributeArguments = [generator.AttributeArgument (generator.MemberAccessExpression (generator.DottedName ("System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes"), stringArguments))];
136136
var attribute = generator.Attribute (
137137
generator.TypeExpression (attributeSymbol), attributeArguments)
138138
.WithAdditionalAnnotations (Simplifier.Annotation, Simplifier.AddImportsAnnotation);
139139

140140
if (addAsReturnAttribute) {
141141
// don't use AddReturnAttribute because it's the same as AddAttribute https://github.com/dotnet/roslyn/pull/63084
142-
editor.ReplaceNode (targetNode, (d, g) => g.AddReturnAttributes (d, new[] { attribute }));
142+
editor.ReplaceNode (targetNode, (d, g) => g.AddReturnAttributes (d, [attribute]));
143143
} else if (addGenericParameterAttribute) {
144144
// AddReturnAttributes currently doesn't support adding attributes to type arguments https://github.com/dotnet/roslyn/pull/63292
145145
var newNode = (TypeParameterSyntax) targetNode;

src/tools/illink/src/ILLink.CodeFix/RequiresHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal static SyntaxNode[] GetAttributeArgumentsForRequires (ISymbol targetSym
1616
if (string.IsNullOrEmpty (symbolDisplayName) || hasPublicAccessibility)
1717
return Array.Empty<SyntaxNode> ();
1818

19-
return new[] { syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}")) };
19+
return [syntaxGenerator.AttributeArgument (syntaxGenerator.LiteralExpression ($"Calls {symbolDisplayName}"))];
2020
}
2121
}
2222
}

src/tools/illink/src/ILLink.CodeFix/UnconditionalSuppressMessageCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected override SyntaxNode[] GetAttributeArguments (ISymbol? attributableSymb
5656
syntaxGenerator.LiteralExpression ("<Pending>"));
5757

5858
// [UnconditionalSuppressWarning (category, id, Justification = "<Pending>")]
59-
return new[] { ruleCategory, ruleId, suppressionJustification };
59+
return [ruleCategory, ruleId, suppressionJustification];
6060
}
6161
}
6262
}

src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal sealed class MemberNotNullAttribute : Attribute
9696
/// <param name="member">
9797
/// The field or property member that is promised to be not-null.
9898
/// </param>
99-
public MemberNotNullAttribute (string member) => Members = new[] { member };
99+
public MemberNotNullAttribute (string member) => Members = [member];
100100

101101
/// <summary>Initializes the attribute with the list of field and property members.</summary>
102102
/// <param name="members">
@@ -122,7 +122,7 @@ internal sealed class MemberNotNullWhenAttribute : Attribute
122122
public MemberNotNullWhenAttribute (bool returnValue, string member)
123123
{
124124
ReturnValue = returnValue;
125-
Members = new[] { member };
125+
Members = [member];
126126
}
127127

128128
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>

src/tools/illink/src/linker/Linker/AssemblyResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ AssemblyDefinition IAssemblyResolver.Resolve (AssemblyNameReference name, Reader
187187
throw new NotSupportedException ();
188188
}
189189

190-
static readonly string[] Extensions = new[] { ".dll", ".exe", ".winmd" };
190+
static readonly string[] Extensions = [".dll", ".exe", ".winmd"];
191191

192192
AssemblyDefinition? SearchDirectory (AssemblyNameReference name)
193193
{

src/tools/illink/src/tlens/TLens/LensesCollection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public Analyzer CreateAnalyzer ()
3737
// Most used/unused attributes
3838
// Constants passed as arguments
3939
//
40-
static readonly LensAnalyzerDetails[] all = new[] {
40+
static readonly LensAnalyzerDetails[] all =
41+
[
4142
new LensAnalyzerDetails ("duplicated-code",
4243
"Methods which are possible duplicates", typeof (DuplicatedCodeAnalyzer)),
4344
new LensAnalyzerDetails ("fields-init",
@@ -64,7 +65,7 @@ public Analyzer CreateAnalyzer ()
6465
"Types with limited number of constructions", typeof (TypeInstatiationAnalyzer)) { DefaultSet = true },
6566
new LensAnalyzerDetails ("unused-param",
6667
"Methods with unused parameters", typeof (UnusedParametersAnalyzer)),
67-
};
68+
];
6869

6970
public static IEnumerable<LensAnalyzerDetails> All => all;
7071

0 commit comments

Comments
 (0)