Skip to content

Updated more code to use C# collection expressions (IDE0300) #7265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ internal static class Utf8MessageProperties
// This uses C# compiler's ability to refer to static data directly.
// For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static
public static ReadOnlySpan<byte> Id
=> new[] { (byte)'i', (byte)'d', };
=> [(byte)'i', (byte)'d',];

public static ReadOnlySpan<byte> Type
=> new[] { (byte)'t', (byte)'y', (byte)'p', (byte)'e', };
=> [(byte)'t', (byte)'y', (byte)'p', (byte)'e',];
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ internal static class Utf8Messages
{
// This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static
public static ReadOnlySpan<byte> ConnectionInitialize =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -21,11 +20,10 @@ internal static class Utf8Messages
(byte)'n',
(byte)'i',
(byte)'t',
};
];

public static ReadOnlySpan<byte> ConnectionAccept =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -40,11 +38,10 @@ internal static class Utf8Messages
(byte)'a',
(byte)'c',
(byte)'k',
};
];

public static ReadOnlySpan<byte> ConnectionError =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -61,11 +58,10 @@ internal static class Utf8Messages
(byte)'r',
(byte)'o',
(byte)'r',
};
];

public static ReadOnlySpan<byte> ConnectionTerminate =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -86,49 +82,44 @@ internal static class Utf8Messages
(byte)'a',
(byte)'t',
(byte)'e',
};
];

public static ReadOnlySpan<byte> Start =>
new[]
{
[
(byte)'s',
(byte)'t',
(byte)'a',
(byte)'r',
(byte)'t',
};
];

public static ReadOnlySpan<byte> Stop =>
new[]
{
[
(byte)'s',
(byte)'t',
(byte)'o',
(byte)'p',
};
];

public static ReadOnlySpan<byte> Data =>
new[]
{
[
(byte)'d',
(byte)'a',
(byte)'t',
(byte)'a',
};
];

public static ReadOnlySpan<byte> Error =>
new[]
{
[
(byte)'e',
(byte)'r',
(byte)'r',
(byte)'o',
(byte)'r',
};
];

public static ReadOnlySpan<byte> Complete =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'m',
Expand All @@ -137,5 +128,5 @@ internal static class Utf8Messages
(byte)'e',
(byte)'t',
(byte)'e',
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ internal static class Utf8MessageProperties
// This uses C# compiler's ability to refer to static data directly.
// For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static
public static ReadOnlySpan<byte> Type
=> new[] { (byte)'t', (byte)'y', (byte)'p', (byte)'e', };
=> [(byte)'t', (byte)'y', (byte)'p', (byte)'e',];

public static ReadOnlySpan<byte> Payload
=> new[] { (byte)'p', (byte)'a', (byte)'y', (byte)'l', (byte)'o', (byte)'a', (byte)'d', };
=> [(byte)'p', (byte)'a', (byte)'y', (byte)'l', (byte)'o', (byte)'a', (byte)'d',];
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ internal static class Utf8Messages
{
// This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static
public static ReadOnlySpan<byte> ConnectionInitialize =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -21,11 +20,10 @@ internal static class Utf8Messages
(byte)'n',
(byte)'i',
(byte)'t',
};
];

public static ReadOnlySpan<byte> ConnectionAccept =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'n',
Expand All @@ -40,11 +38,10 @@ internal static class Utf8Messages
(byte)'a',
(byte)'c',
(byte)'k',
};
];

public static ReadOnlySpan<byte> Subscribe =>
new[]
{
[
(byte)'s',
(byte)'u',
(byte)'b',
Expand All @@ -54,30 +51,27 @@ internal static class Utf8Messages
(byte)'i',
(byte)'b',
(byte)'e',
};
];

public static ReadOnlySpan<byte> Next =>
new[]
{
[
(byte)'n',
(byte)'e',
(byte)'x',
(byte)'t',
};
];

public static ReadOnlySpan<byte> Error =>
new[]
{
[
(byte)'e',
(byte)'r',
(byte)'r',
(byte)'o',
(byte)'r',
};
];

public static ReadOnlySpan<byte> Complete =>
new[]
{
[
(byte)'c',
(byte)'o',
(byte)'m',
Expand All @@ -86,23 +80,21 @@ internal static class Utf8Messages
(byte)'e',
(byte)'t',
(byte)'e',
};
];

public static ReadOnlySpan<byte> Ping =>
new[]
{
[
(byte)'p',
(byte)'i',
(byte)'n',
(byte)'g',
};
];

public static ReadOnlySpan<byte> Pong =>
new[]
{
[
(byte)'p',
(byte)'o',
(byte)'n',
(byte)'g',
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static IReadOnlyList<TypeComponent> Decompose(
? current
: ExtendedType.Tools.ChangeNullability(
current,
new bool?[] { true, },
[true,],
cache);

list.Add((TypeComponentKind.List, rewritten));
Expand All @@ -78,7 +78,7 @@ private static IReadOnlyList<TypeComponent> Decompose(
? current
: ExtendedType.Tools.ChangeNullability(
current,
new bool?[] { true, },
[true,],
cache);

list.Add((TypeComponentKind.Named, rewritten));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public sealed class BindableList<T> : IBindableList<T>
{
#if NET6_0_OR_GREATER
private static readonly T[] _empty = new T[0];
private static readonly T[] _empty = [];

Check warning on line 14 in src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/BindableList.cs

View check run for this annotation

Codecov / codecov/patch

src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/BindableList.cs#L14

Added line #L14 was not covered by tests
#endif

private List<T>? _list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void From_SystemType_List()
typeof(NativeType<List<byte?>>),
_cache);
list = ExtendedType.Tools.ChangeNullability(
list, new bool?[] { false, }, _cache);
list, [false,], _cache);

var nullableList = ExtendedType.FromType(
typeof(List<byte?>),
Expand Down Expand Up @@ -337,7 +337,7 @@ public void ChangeNullability_From_ElementType(Type listType)
// act
IExtendedType list = ExtendedType.FromType(listType, _cache);
list = ExtendedType.Tools.ChangeNullability(
list, new bool?[] { null, false, }, _cache);
list, [null, false,], _cache);

// assert
Assert.False(list.ElementType!.IsNullable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void Create_ScalarArrayAnyStringEqual_Expression()
var a = new Bar { Foo = new Foo { ScalarArray = ["c", "d", "a",], }, };
Assert.True(func(a));

var b = new Bar { Foo = new Foo { ScalarArray = new string[0], }, };
var b = new Bar { Foo = new Foo { ScalarArray = [], }, };
Assert.False(func(b));

var c = new Bar { Foo = new Foo { ScalarArray = null, }, };
Expand Down Expand Up @@ -369,7 +369,7 @@ public void Create_ArrayObjectNestedArrayAnyStringEqual_Expression()
[
new Bar {
Foo = new Foo {
ScalarArray = new string[0],
ScalarArray = [],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,41 @@ protected override void Configure(IFilterInputTypeDescriptor descriptor)

public class Foo
{
public Baz[] Baz { get; set; } = new Baz[0];
public Baz[] Baz { get; set; } = [];

public string[] StringArray { get; set; } = new string[0];
public string[] StringArray { get; set; } = [];

public string?[] StringNullableArray { get; set; } = new string?[0];
public string?[] StringNullableArray { get; set; } = [];

public bool[] BooleanArray { get; set; } = new bool[0];
public bool[] BooleanArray { get; set; } = [];

public bool?[] BooleanNullableArray { get; set; } = new bool?[0];
public bool?[] BooleanNullableArray { get; set; } = [];

public short[] BarShortArray { get; set; } = new short[0];
public short[] BarShortArray { get; set; } = [];

public int[] BarIntArray { get; set; } = new int[0];
public int[] BarIntArray { get; set; } = [];

public long[] BarLongArray { get; set; } = new long[0];
public long[] BarLongArray { get; set; } = [];

public float[] BarFloatArray { get; set; } = new float[0];
public float[] BarFloatArray { get; set; } = [];

public double[] BarDoubleArray { get; set; } = new double[0];
public double[] BarDoubleArray { get; set; } = [];

public decimal[] BarDecimalArray { get; set; } = new decimal[0];
public decimal[] BarDecimalArray { get; set; } = [];

public short?[] BarShortNullableArray { get; set; } = new short?[0];
public short?[] BarShortNullableArray { get; set; } = [];

public int?[] BarIntNullableArray { get; set; } = new int?[0];
public int?[] BarIntNullableArray { get; set; } = [];

public long?[] BarLongNullableArray { get; set; } = new long?[0];
public long?[] BarLongNullableArray { get; set; } = [];

public float?[] BarFloatNullableArray { get; set; } = new float?[0];
public float?[] BarFloatNullableArray { get; set; } = [];

public double?[] BarDoubleNullableArray { get; set; } = new double?[0];
public double?[] BarDoubleNullableArray { get; set; } = [];

public decimal?[] BarDecimalNullableArray { get; set; } = new decimal?[0];
public decimal?[] BarDecimalNullableArray { get; set; } = [];

public FooBar[] FooBarArray { get; set; } = new FooBar[0];
public FooBar[] FooBarArray { get; set; } = [];
}

public class Baz
Expand Down
Loading
Loading