Skip to content

Commit 95b9776

Browse files
filzrevtimcassell
andauthored
chore: fix IDE0028/IDE0300/IDE0301/IDE0303 that are reported by .NET analyzer (#3016)
* chore: fix IDE0028 that reported by analyzer * chore: fix IDE0300, IDE0301, IDE0303 * Update tests/BenchmarkDotNet.Tests/CorrectionsSuggesterTests.cs --------- Co-authored-by: Tim Cassell <cassell.timothy@gmail.com>
1 parent aa44dc4 commit 95b9776

File tree

149 files changed

+873
-866
lines changed

Some content is hidden

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

149 files changed

+873
-866
lines changed

samples/BenchmarkDotNet.Samples/IntroComparableComplexParam.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class IntroComparableComplexParam
99
[ParamsSource(nameof(ValuesForA))]
1010
public ComplexParam? A { get; set; }
1111

12-
public IEnumerable<ComplexParam> ValuesForA => new[] { new ComplexParam(1, "First"), new ComplexParam(2, "Second") };
12+
public IEnumerable<ComplexParam> ValuesForA => [new ComplexParam(1, "First"), new ComplexParam(2, "Second")];
1313

1414
[Benchmark]
1515
public object? Benchmark() => A;

samples/BenchmarkDotNet.Samples/IntroCustomMonoArguments.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public ConfigWithCustomArguments()
1919

2020
AddJob(Job.Default
2121
.WithRuntime(MonoRuntime.Default)
22-
.WithArguments(new[] { new MonoArgument("--optimize=inline") })
22+
.WithArguments([new MonoArgument("--optimize=inline")])
2323
.WithId("Inlining enabled"));
2424
AddJob(Job.Default
2525
.WithRuntime(MonoRuntime.Default)
26-
.WithArguments(new[] { new MonoArgument("--optimize=-inline") })
26+
.WithArguments([new MonoArgument("--optimize=-inline")])
2727
.WithId("Inlining disabled"));
2828
}
2929
}

samples/BenchmarkDotNet.Samples/IntroDeferredExecution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BenchmarkDotNet.Samples
77
{
88
public class IntroDeferredExecution
99
{
10-
private readonly int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
10+
private readonly int[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1111

1212
private readonly Consumer consumer = new Consumer();
1313

samples/BenchmarkDotNet.Samples/IntroInliningDiagnoser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace BenchmarkDotNet.Samples
55
{
6-
[Diagnostics.Windows.Configs.InliningDiagnoser(logFailuresOnly: false, allowedNamespaces: new[] { "BenchmarkDotNet.Samples" })]
6+
[Diagnostics.Windows.Configs.InliningDiagnoser(logFailuresOnly: false, allowedNamespaces: ["BenchmarkDotNet.Samples"])]
77
public class IntroInliningDiagnoser
88
{
99
[Benchmark]

samples/BenchmarkDotNet.Samples/IntroParamsSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class IntroParamsSource
1515
public int B;
1616

1717
// public property
18-
public IEnumerable<int> ValuesForA => new[] { 100, 200 };
18+
public IEnumerable<int> ValuesForA => [100, 200];
1919

2020
// public static method
21-
public static IEnumerable<int> ValuesForB() => new[] { 10, 20 };
21+
public static IEnumerable<int> ValuesForB() => [10, 20];
2222

2323
// public field getting its params from a method in another type
2424
[ParamsSource(typeof(ParamsValues), nameof(ParamsValues.ValuesForC))]
@@ -30,6 +30,6 @@ public class IntroParamsSource
3030

3131
public static class ParamsValues
3232
{
33-
public static IEnumerable<int> ValuesForC() => new[] { 1000, 2000 };
33+
public static IEnumerable<int> ValuesForC() => [1000, 2000];
3434
}
3535
}

src/BenchmarkDotNet.Annotations/Attributes/ArgumentsAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class ArgumentsAttribute : PriorityAttribute
1010

1111
// CLS-Compliant Code requires a constructor without an array in the argument list
1212
[PublicAPI]
13-
public ArgumentsAttribute() => Values = new object[0];
13+
public ArgumentsAttribute() => Values = [];
1414

1515
public ArgumentsAttribute(params object?[]? values)
16-
=> Values = values ?? new object?[] { null }; // when users do Arguments(null) they mean one, null argument
16+
=> Values = values ?? [null]; // when users do Arguments(null) they mean one, null argument
1717
}
1818
}

src/BenchmarkDotNet.Annotations/Attributes/BenchmarkCategoryAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BenchmarkCategoryAttribute : Attribute
99
public string[] Categories { get; }
1010

1111
// CLS-Compliant Code requires a constructor without an array in the argument list
12-
[PublicAPI] protected BenchmarkCategoryAttribute() => Categories = new string[0];
12+
[PublicAPI] protected BenchmarkCategoryAttribute() => Categories = [];
1313

1414
public BenchmarkCategoryAttribute(params string[] categories) => Categories = categories;
1515
}

src/BenchmarkDotNet.Annotations/Attributes/GenericTypeArgumentsAttribute.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public class GenericTypeArgumentsAttribute : Attribute
99
public Type[] GenericTypeArguments { get; }
1010

1111
public GenericTypeArgumentsAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
12-
=> GenericTypeArguments = new[] { type };
12+
=> GenericTypeArguments = [type];
1313

1414
public GenericTypeArgumentsAttribute(
1515
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type1,
1616
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type2)
17-
=> GenericTypeArguments = new[] { type1, type2 };
17+
=> GenericTypeArguments = [type1, type2];
1818

1919
public GenericTypeArgumentsAttribute(
2020
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type1,
2121
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type2,
2222
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type3)
23-
=> GenericTypeArguments = new[] { type1, type2, type3 };
23+
=> GenericTypeArguments = [type1, type2, type3];
2424
}
2525
}

src/BenchmarkDotNet.Annotations/Attributes/TargetedAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace BenchmarkDotNet.Attributes
99
/// </summary>
1010
public abstract class TargetedAttribute : Attribute
1111
{
12-
public string[] Targets { get; set; } = new string[0];
12+
public string[] Targets { get; set; } = [];
1313

1414
/// <summary>
1515
/// Target method for attribute
1616
/// </summary>
1717
public string Target
1818
{
1919
get => throw new InvalidOperationException("Please use Targets property"); // kept to keep compiler happy "Named attribute arguments must be fields which are not readonly, static, or const, or read-write properties which are public and not static."
20-
set => Targets = string.IsNullOrEmpty(value) ? new string[0] : value.Split(','); // , is for backward compat
20+
set => Targets = string.IsNullOrEmpty(value) ? [] : value.Split(','); // , is for backward compat
2121
}
2222

2323
public bool Match(MethodInfo method) => Targets.Length == 0 || Targets.Contains(method.Name);

src/BenchmarkDotNet.Diagnostics.Windows/ConcurrencyVisualizerProfiler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class ConcurrencyVisualizerProfiler : IProfiler
3333
private static readonly Guid ConcurrencyVisualizerMarkersId = new Guid("8D4925AB-505A-483b-A7E0-6F824A07A6F0"); // "ConcurrencyVisualizer.Markers";
3434

3535
private readonly EtwProfiler etwProfiler;
36-
private readonly Dictionary<BenchmarkCase, string> benchmarkToCvTraceFile = new Dictionary<BenchmarkCase, string>();
37-
private readonly Dictionary<BenchmarkCase, int> benchmarkToProcessId = new Dictionary<BenchmarkCase, int>();
36+
private readonly Dictionary<BenchmarkCase, string> benchmarkToCvTraceFile = [];
37+
private readonly Dictionary<BenchmarkCase, int> benchmarkToProcessId = [];
3838

3939
[PublicAPI] // parameterless ctor required by DiagnosersLoader to support creating this profiler via console line args
4040
public ConcurrencyVisualizerProfiler() => etwProfiler = new EtwProfiler(CreateDefaultConfig());
@@ -44,11 +44,11 @@ public class ConcurrencyVisualizerProfiler : IProfiler
4444

4545
public string ShortName => "CV";
4646

47-
public IEnumerable<string> Ids => new[] { nameof(ConcurrencyVisualizerProfiler) };
47+
public IEnumerable<string> Ids => [nameof(ConcurrencyVisualizerProfiler)];
4848

49-
public IEnumerable<IExporter> Exporters => Array.Empty<IExporter>();
49+
public IEnumerable<IExporter> Exporters => [];
5050

51-
public IEnumerable<IAnalyser> Analysers => Array.Empty<IAnalyser>();
51+
public IEnumerable<IAnalyser> Analysers => [];
5252

5353
public void DisplayResults(ILogger logger)
5454
{

0 commit comments

Comments
 (0)