Skip to content

Commit 5de2652

Browse files
committed
Convert CodeBase to collection Expressions
1 parent 9e29af2 commit 5de2652

File tree

170 files changed

+2114
-2102
lines changed

Some content is hidden

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

170 files changed

+2114
-2102
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ csharp_using_directive_placement = outside_namespace:warning
177177
csharp_prefer_static_local_function = true:warning
178178
# Primary constructor preferences
179179
csharp_style_prefer_primary_constructors = false:none
180+
# Collection preferences
181+
dotnet_style_prefer_collection_expression = true:error
182+
resharper_use_collection_expression_highlighting =true:error
183+
184+
180185

181186
##########################################
182187
# Unnecessary Code Rules

src/ImageSharp/Color/Color.WebSafePalette.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public partial struct Color
1515
/// </summary>
1616
public static ReadOnlyMemory<Color> WebSafePalette => WebSafePaletteLazy.Value;
1717

18-
private static Color[] CreateWebSafePalette() => new[]
19-
{
18+
private static Color[] CreateWebSafePalette() =>
19+
[
2020
AliceBlue,
2121
AntiqueWhite,
2222
Aqua,
@@ -159,5 +159,5 @@ private static Color[] CreateWebSafePalette() => new[]
159159
WhiteSmoke,
160160
Yellow,
161161
YellowGreen
162-
};
162+
];
163163
}

src/ImageSharp/Color/Color.WernerPalette.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public partial struct Color
1616
/// </summary>
1717
public static ReadOnlyMemory<Color> WernerPalette => WernerPaletteLazy.Value;
1818

19-
private static Color[] CreateWernerPalette() => new[]
20-
{
19+
private static Color[] CreateWernerPalette() =>
20+
[
2121
ParseHex("#f1e9cd"),
2222
ParseHex("#f2e7cf"),
2323
ParseHex("#ece6d0"),
@@ -128,5 +128,5 @@ private static Color[] CreateWernerPalette() => new[]
128128
ParseHex("#9b856b"),
129129
ParseHex("#766051"),
130130
ParseHex("#453b32")
131-
};
131+
];
132132
}

src/ImageSharp/Common/Helpers/HexConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static int FromChar(int c)
3535
{
3636
// Map from an ASCII char to its hex value, e.g. arr['b'] == 11. 0xFF means it's not a hex digit.
3737
// This doesn't actually allocate.
38-
ReadOnlySpan<byte> charToHexLookup = new byte[]
39-
{
38+
ReadOnlySpan<byte> charToHexLookup =
39+
[
4040
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 15
4141
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 31
4242
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 47
@@ -52,8 +52,8 @@ static int FromChar(int c)
5252
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 207
5353
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 223
5454
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 239
55-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 255
56-
};
55+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 255
56+
];
5757

5858
return (uint)c >= (uint)charToHexLookup.Length ? 0xFF : charToHexLookup[c];
5959
}

src/ImageSharp/Common/InlineArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

44
// <auto-generated />

src/ImageSharp/Common/InlineArray.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp;
1616
<#GenerateInlineArrays();#>
1717

1818
<#+
19-
private static int[] Lengths = new int[] {4, 8, 16 };
19+
private static int[] Lengths = [4, 8, 16 ];
2020

2121
void GenerateInlineArrays()
2222
{

src/ImageSharp/Compression/Zlib/Adler32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ internal static class Adler32
3232
private const int BlockSize = 1 << 5;
3333

3434
// The C# compiler emits this as a compile-time constant embedded in the PE file.
35-
private static ReadOnlySpan<byte> Tap1Tap2 => new byte[]
36-
{
35+
private static ReadOnlySpan<byte> Tap1Tap2 =>
36+
[
3737
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, // tap1
3838
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 // tap2
39-
};
39+
];
4040

4141
/// <summary>
4242
/// Calculates the Adler32 checksum with the bytes taken from the span.

src/ImageSharp/Compression/Zlib/DeflaterConstants.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,25 @@ internal static class DeflaterConstants
124124
/// <summary>
125125
/// Internal compression engine constant
126126
/// </summary>
127-
public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8, 8, 8, 32, 32 };
127+
public static int[] GOOD_LENGTH = [0, 4, 4, 4, 4, 8, 8, 8, 32, 32];
128128

129129
/// <summary>
130130
/// Internal compression engine constant
131131
/// </summary>
132-
public static int[] MAX_LAZY = { 0, 4, 5, 6, 4, 16, 16, 32, 128, 258 };
132+
public static int[] MAX_LAZY = [0, 4, 5, 6, 4, 16, 16, 32, 128, 258];
133133

134134
/// <summary>
135135
/// Internal compression engine constant
136136
/// </summary>
137-
public static int[] NICE_LENGTH = { 0, 8, 16, 32, 16, 32, 128, 128, 258, 258 };
137+
public static int[] NICE_LENGTH = [0, 8, 16, 32, 16, 32, 128, 128, 258, 258];
138138

139139
/// <summary>
140140
/// Internal compression engine constant
141141
/// </summary>
142-
public static int[] MAX_CHAIN = { 0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096 };
142+
public static int[] MAX_CHAIN = [0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096];
143143

144144
/// <summary>
145145
/// Internal compression engine constant
146146
/// </summary>
147-
public static int[] COMPR_FUNC = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
147+
public static int[] COMPR_FUNC = [0, 1, 1, 1, 1, 2, 2, 2, 2, 2];
148148
}

src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)
7777

7878
// See RFC 1951 3.2.6
7979
// Literal codes
80-
private static readonly short[] StaticLCodes = new short[]
81-
{
80+
private static readonly short[] StaticLCodes =
81+
[
8282
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
8383
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
8484
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
@@ -97,10 +97,10 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)
9797
31, 287, 159, 415, 95, 351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511,
9898
0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36,
9999
100, 20, 84, 52, 116, 3, 131, 67, 195, 35, 163
100-
};
100+
];
101101

102-
private static ReadOnlySpan<byte> StaticLLength => new byte[]
103-
{
102+
private static ReadOnlySpan<byte> StaticLLength =>
103+
[
104104
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
105105
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
106106
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
@@ -119,34 +119,34 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)
119119
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
120120
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
121121
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8
122-
};
122+
];
123123

124124
// Distance codes and lengths.
125-
private static readonly short[] StaticDCodes = new short[]
126-
{
125+
private static readonly short[] StaticDCodes =
126+
[
127127
0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14,
128128
30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23
129-
};
129+
];
130130

131-
private static ReadOnlySpan<byte> StaticDLength => new byte[]
132-
{
131+
private static ReadOnlySpan<byte> StaticDLength =>
132+
[
133133
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
134134
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
135-
};
135+
];
136136
#pragma warning restore SA1201 // Elements should appear in the correct order
137137

138138
/// <summary>
139139
/// Gets the lengths of the bit length codes are sent in order of decreasing probability, to avoid transmitting the lengths for unused bit length codes.
140140
/// </summary>
141-
private static ReadOnlySpan<byte> BitLengthOrder => new byte[]
142-
{
141+
private static ReadOnlySpan<byte> BitLengthOrder =>
142+
[
143143
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
144-
};
144+
];
145145

146-
private static ReadOnlySpan<byte> Bit4Reverse => new byte[]
147-
{
146+
private static ReadOnlySpan<byte> Bit4Reverse =>
147+
[
148148
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
149-
};
149+
];
150150

151151
/// <summary>
152152
/// Gets the pending buffer to use.

src/ImageSharp/Formats/Bmp/BmpConstants.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ internal static class BmpConstants
1111
/// <summary>
1212
/// The list of mimetypes that equate to a bmp.
1313
/// </summary>
14-
public static readonly IEnumerable<string> MimeTypes = new[]
15-
{
14+
public static readonly IEnumerable<string> MimeTypes =
15+
[
1616
"image/bmp",
1717
"image/x-windows-bmp",
1818
"image/x-win-bitmap"
19-
};
19+
];
2020

2121
/// <summary>
2222
/// The list of file extensions that equate to a bmp.
2323
/// </summary>
24-
public static readonly IEnumerable<string> FileExtensions = new[] { "bm", "bmp", "dip" };
24+
public static readonly IEnumerable<string> FileExtensions = ["bm", "bmp", "dip"];
2525

2626
/// <summary>
2727
/// Valid magic bytes markers identifying a Bitmap file.

0 commit comments

Comments
 (0)