Skip to content

Commit 4af1bd8

Browse files
committed
Uses collection expressions for array initialization
Updates the code to use collection expressions for initializing arrays, improving code readability and conciseness.
1 parent c05fbf4 commit 4af1bd8

23 files changed

+130
-98
lines changed

src/Exceptionless.DateTimeExtensions/FormatParsers/FormatParsers/Helper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ internal static class Helper
1010
internal static readonly string PluralTimeNames = "minutes|hours|days|weeks|months|years";
1111
internal static readonly string AllTimeNames = SingularTimeNames + "|" + PluralTimeNames;
1212
internal static readonly string RelationNames = "this|past|last|next|previous";
13-
internal static readonly List<string> MonthNames = new(new[] { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" });
13+
internal static readonly List<string> MonthNames =
14+
[
15+
..new[]
16+
{
17+
"january", "february", "march", "april", "may", "june", "july", "august", "september", "october",
18+
"november", "december"
19+
}
20+
];
1421

1522
internal static TimeSpan GetTimeSpanFromName(string name)
1623
{

src/Exceptionless.DateTimeExtensions/TypeHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static IList<Type> SortByPriority(this IEnumerable<Type> types)
2121
internal static IEnumerable<Type> GetDerivedTypes<TAction>(IEnumerable<Assembly> assemblies = null)
2222
{
2323
if (assemblies == null)
24-
assemblies = new[] { typeof(TypeHelper).GetTypeInfo().Assembly };
24+
assemblies = [typeof(TypeHelper).GetTypeInfo().Assembly];
2525

2626
var types = new List<Type>();
2727
foreach (var assembly in assemblies)

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/ExplicitDateFormatParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "2014-02-01", _now.Change(null, 2, 1).StartOfDay(), _now.Change(null, 2, 1).EndOfDay() },
24+
return
25+
[
26+
["2014-02-01", _now.Change(null, 2, 1).StartOfDay(), _now.Change(null, 2, 1).EndOfDay()],
2627
["2014-02-01T05", _now.Change(null, 2, 1, 5).StartOfHour(), _now.Change(null, 2, 1, 5).EndOfHour()],
2728
["2014-02-01T05:30", _now.Change(null, 2, 1, 5, 30).StartOfMinute(), _now.Change(null, 2, 1, 5, 30).EndOfMinute()],
2829
["2014-02-01T05:30:20", _now.Change(null, 2, 1, 5, 30, 20).StartOfSecond(), _now.Change(null, 2, 1, 5, 30, 20).EndOfSecond()],
@@ -33,7 +34,7 @@ public static IEnumerable<object[]> Inputs
3334
["2014-12-45", null, null],
3435
["blah", null, null],
3536
["blah blah", null, null]
36-
};
37+
];
3738
}
3839
}
3940
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/MonthDayFormatParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "02-01", _now.Change(null, 2, 1).StartOfDay(), _now.Change(null, 2, 1).EndOfDay() },
24+
return
25+
[
26+
["02-01", _now.Change(null, 2, 1).StartOfDay(), _now.Change(null, 2, 1).EndOfDay()],
2627
["11-06", _now.Change(null, 11, 6).StartOfDay(), _now.Change(null, 11, 6).EndOfDay()],
2728
["12-24", _now.Change(null, 12, 24).StartOfDay(), _now.Change(null, 12, 24).EndOfDay()],
2829
["12-45", null, null],
2930
["blah", null, null],
3031
["blah blah", null, null]
31-
};
32+
];
3233
}
3334
}
3435
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/MonthFormatParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "jan", _now.ChangeMonth(1).StartOfMonth(), _now.ChangeMonth(1).EndOfMonth() },
24+
return
25+
[
26+
["jan", _now.ChangeMonth(1).StartOfMonth(), _now.ChangeMonth(1).EndOfMonth()],
2627
["nov", _now.StartOfMonth(), _now.EndOfMonth()],
2728
["decemBer", _now.ChangeMonth(12).StartOfMonth(), _now.ChangeMonth(12).EndOfMonth()],
2829
["blah", null, null],
2930
["blah blah", null, null]
30-
};
31+
];
3132
}
3233
}
3334
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/MonthRelationFormatParserTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "this janUary", _now.AddYears(1).ChangeMonth(1).StartOfMonth(), _now.AddYears(1).ChangeMonth(1).EndOfMonth() },
24+
return
25+
[
26+
["this janUary", _now.AddYears(1).ChangeMonth(1).StartOfMonth(), _now.AddYears(1).ChangeMonth(1).EndOfMonth()
27+
],
2628
["last jan", _now.ChangeMonth(1).StartOfMonth(), _now.ChangeMonth(1).EndOfMonth()],
2729
["next januaRY", _now.AddYears(1).ChangeMonth(1).StartOfMonth(), _now.AddYears(1).ChangeMonth(1).EndOfMonth()],
2830
["this november", _now.StartOfMonth(), _now.EndOfMonth()],
@@ -31,7 +33,7 @@ public static IEnumerable<object[]> Inputs
3133
["last november", _now.SubtractYears(1).StartOfMonth(), _now.SubtractYears(1).EndOfMonth()],
3234
["blah", null, null],
3335
["blah blah", null, null]
34-
};
36+
];
3537
}
3638
}
3739
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/NamedDayFormatParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "yesterday", _now.SubtractDays(1).StartOfDay(), _now.SubtractDays(1).EndOfDay() },
24+
return
25+
[
26+
["yesterday", _now.SubtractDays(1).StartOfDay(), _now.SubtractDays(1).EndOfDay()],
2627
["today", _now.StartOfDay(), _now.EndOfDay()],
2728
["tomorrow", _now.AddDays(1).StartOfDay(), _now.AddDays(1).EndOfDay()],
2829
["blah", null, null],
2930
["blah blah", null, null]
30-
};
31+
];
3132
}
3233
}
3334
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/PartParsers/AmountTimeRelationPartParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "1 minute ago", false, _now.SubtractMinutes(1).StartOfMinute() },
24+
return
25+
[
26+
["1 minute ago", false, _now.SubtractMinutes(1).StartOfMinute()],
2627
["1 minute ago", true, _now.SubtractMinutes(1).EndOfMinute()],
2728
["1 minute from now", false, _now.AddMinutes(1).StartOfMinute()],
2829
["1 minute from now", true, _now.AddMinutes(1).EndOfMinute()],
@@ -32,7 +33,7 @@ public static IEnumerable<object[]> Inputs
3233
["12 days from now", true, _now.AddDays(12).EndOfDay()],
3334
["blah", false, null],
3435
["blah blah", true, null]
35-
};
36+
];
3637
}
3738
}
3839
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/PartParsers/DateMathPartParserTests.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public static IEnumerable<object[]> NowInputs
5656
{
5757
get
5858
{
59-
return new[] {
59+
return
60+
[
6061
// Basic "now" anchor
61-
new object[] { "now", false, _now },
62+
["now", false, _now],
6263
["now", true, _now],
6364

6465
// Now with single operations
@@ -106,7 +107,7 @@ public static IEnumerable<object[]> NowInputs
106107
["now-d", true, _now.AddDays(-1)],
107108
["now+M", false, _now.AddMonths(1)],
108109
["now-y", true, _now.AddYears(-1)]
109-
};
110+
];
110111
}
111112
}
112113

@@ -116,9 +117,10 @@ public static IEnumerable<object[]> ExplicitDateInputs
116117
{
117118
var baseDate = new DateTimeOffset(2001, 2, 1, 0, 0, 0, _now.Offset);
118119

119-
return new[] {
120+
return
121+
[
120122
// Basic explicit date formats (officially supported by Elasticsearch)
121-
new object[] { "2001-02-01||", false, baseDate },
123+
["2001-02-01||", false, baseDate],
122124
["2001-02-01||", true, baseDate],
123125
["20010201||", false, baseDate],
124126
["20010201||", true, baseDate],
@@ -170,17 +172,18 @@ public static IEnumerable<object[]> ExplicitDateInputs
170172
// Basic format variations (yyyyMMdd is officially supported)
171173
["20230615||", false, new DateTimeOffset(2023, 6, 15, 0, 0, 0, _now.Offset)],
172174
["20230615||", true, new DateTimeOffset(2023, 6, 15, 0, 0, 0, _now.Offset)]
173-
};
175+
];
174176
}
175177
}
176178

177179
public static IEnumerable<object[]> ComplexOperationInputs
178180
{
179181
get
180182
{
181-
return new[] {
183+
return
184+
[
182185
// Multiple operations
183-
new object[] { "now+1d+1h", false, _now.AddDays(1).AddHours(1) },
186+
["now+1d+1h", false, _now.AddDays(1).AddHours(1)],
184187
["now+1d+1h", true, _now.AddDays(1).AddHours(1)],
185188
["now-1d-1h", false, _now.AddDays(-1).AddHours(-1)],
186189
["now-1d-1h", true, _now.AddDays(-1).AddHours(-1)],
@@ -208,17 +211,18 @@ public static IEnumerable<object[]> ComplexOperationInputs
208211
// Complex operations with timezone offsets
209212
["2023-06-15T10:00:00+05:00||+1d-2h", false, new DateTimeOffset(2023, 6, 16, 8, 0, 0, TimeSpan.FromHours(5))],
210213
["2023-06-15T10:00:00+05:00||+1d-2h", true, new DateTimeOffset(2023, 6, 16, 8, 0, 0, TimeSpan.FromHours(5))]
211-
};
214+
];
212215
}
213216
}
214217

215218
public static IEnumerable<object[]> RoundingInputs
216219
{
217220
get
218221
{
219-
return new[] {
222+
return
223+
[
220224
// Rounding to different units
221-
new object[] { "now/d", false, _now.StartOfDay() },
225+
["now/d", false, _now.StartOfDay()],
222226
["now/d", true, _now.EndOfDay()],
223227
["now/h", false, _now.StartOfHour()],
224228
["now/h", true, _now.EndOfHour()],
@@ -244,17 +248,18 @@ public static IEnumerable<object[]> RoundingInputs
244248
// Multiple operations ending with rounding
245249
["now+1M-1d/d", false, _now.AddMonths(1).AddDays(-1).StartOfDay()],
246250
["now+1M-1d/d", true, _now.AddMonths(1).AddDays(-1).EndOfDay()]
247-
};
251+
];
248252
}
249253
}
250254

251255
public static IEnumerable<object[]> EdgeCaseInputs
252256
{
253257
get
254258
{
255-
return new[] {
259+
return
260+
[
256261
// Case sensitivity
257-
new object[] { "NOW", false, _now },
262+
["NOW", false, _now],
258263
["NOW", true, _now],
259264
["Now", false, _now],
260265
["Now", true, _now],
@@ -278,17 +283,18 @@ public static IEnumerable<object[]> EdgeCaseInputs
278283
["now+1D", true, null],
279284
["now+1HOUR", false, null], // Should fail - single char required
280285
["now+1HOUR", true, null]
281-
};
286+
];
282287
}
283288
}
284289

285290
public static IEnumerable<object[]> InvalidInputs
286291
{
287292
get
288293
{
289-
return new[] {
294+
return
295+
[
290296
// Invalid formats
291-
new object[] { "invalid", false, null },
297+
["invalid", false, null],
292298
["invalid", true, null],
293299
["blah", false, null],
294300
["blah blah", true, null],
@@ -329,7 +335,7 @@ public static IEnumerable<object[]> InvalidInputs
329335
["2023-01-32||", true, null],
330336
["2023-02-29||", false, null], // Invalid day for non-leap year
331337
["2023-02-29||", true, null]
332-
};
338+
];
333339
}
334340
}
335341
}

tests/Exceptionless.DateTimeExtensions.Tests/FormatParsers/PartParsers/ExplicitDatePartParserTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public static IEnumerable<object[]> Inputs
2121
{
2222
get
2323
{
24-
return new[] {
25-
new object[] { "2014-02-01", false, _now.Change(null, 2, 1).StartOfDay() },
24+
return
25+
[
26+
["2014-02-01", false, _now.Change(null, 2, 1).StartOfDay()],
2627
["2014-02-01", true, _now.Change(null, 2, 1).EndOfDay()],
2728
["2014-02-01T05", false, _now.Change(null, 2, 1, 5).StartOfHour()],
2829
["2014-02-01T05", true, _now.Change(null, 2, 1, 5).EndOfHour()],
@@ -41,7 +42,7 @@ public static IEnumerable<object[]> Inputs
4142
["2014-12-45", true, null],
4243
["blah", false, null],
4344
["blah blah", true, null]
44-
};
45+
];
4546
}
4647
}
4748
}

0 commit comments

Comments
 (0)