CA1825: use Array.Empty instead of new [0].

This commit is contained in:
Huo Yaoyuan
2019-11-17 23:19:31 +08:00
parent 4d7a3d3a51
commit 34ec36c2f0
7 changed files with 9 additions and 9 deletions

View File

@@ -71,7 +71,4 @@
<Rule Id="CA2237" Action="None" />
<Rule Id="CA5351" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.CSharp.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1825" Action="None" />
</Rules>
</RuleSet>

View File

@@ -38,7 +38,9 @@ namespace osu.Framework.Tests.Lists
public void TestEmptyJaggedToRectangular()
{
int[,] result = null;
Assert.DoesNotThrow(() => result = new int[0][].ToRectangular());
#pragma warning disable CA1825 // Avoid zero-length array allocations.
Assert.DoesNotThrow(() => result = new int[0][].ToRectangular()); // Not natural for the APi shape
#pragma warning restore CA1825 // Avoid zero-length array allocations.
Assert.AreEqual(0, result.Length);
}

View File

@@ -36,7 +36,7 @@ namespace osu.Framework.Tests.MathUtils
Assert.Throws<ArgumentException>(() =>
{
ReadOnlySpan<Vector2> list = new Vector2[0];
ReadOnlySpan<Vector2> list = Array.Empty<Vector2>();
Interpolation.Lagrange(list, 4);
});

View File

@@ -131,7 +131,7 @@ namespace osu.Framework.Tests.Visual.Layout
var method =
GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).SingleOrDefault(m => m.GetCustomAttribute<FlowTestCaseAttribute>()?.TestType == testType);
if (method != null)
method.Invoke(this, new object[0]);
method.Invoke(this, Array.Empty<object>());
}
private void buildTest()

View File

@@ -59,7 +59,7 @@ namespace osu.Framework.Graphics.Transforms
private static ReadFunc createPropertyGetter(MethodInfo getter)
{
if (!RuntimeInfo.SupportsJIT) return transformable => (TValue)getter.Invoke(transformable, new object[0]);
if (!RuntimeInfo.SupportsJIT) return transformable => (TValue)getter.Invoke(transformable, Array.Empty<object>());
return (ReadFunc)getter.CreateDelegate(typeof(ReadFunc));
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using osu.Framework.Input.Handlers;
using osu.Framework.Logging;
@@ -59,7 +60,7 @@ namespace osu.Framework.Platform
base.UpdateFrame();
}
protected override IEnumerable<InputHandler> CreateAvailableInputHandlers() => new InputHandler[] { };
protected override IEnumerable<InputHandler> CreateAvailableInputHandlers() => Array.Empty<InputHandler>();
private class FastClock : IClock
{

View File

@@ -364,7 +364,7 @@ namespace osu.Framework.Testing
// should run inline where possible. this is to fix RunAllSteps potentially finding no steps if the steps are added in LoadComplete (else they get forcefully scheduled too late)
private void schedule(Action action) => Scheduler.Add(action, false);
public virtual IReadOnlyList<Type> RequiredTypes => new Type[] { };
public virtual IReadOnlyList<Type> RequiredTypes => Array.Empty<Type>();
internal void RunSetUpSteps()
{