Skip to content

Commit 7298d22

Browse files
committed
Cleanup
1 parent 87f816d commit 7298d22

File tree

56 files changed

+205
-166
lines changed

Some content is hidden

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

56 files changed

+205
-166
lines changed

CodeJam.Main.Tests/IO/PathHelperTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,20 @@ public enum PathKind
106106
[TestCase(@"a\:a", PathKind.ValidRelativePath)]
107107
[TestCase(@"a\|a", PathKind.ValidRelativePath)]
108108
#else
109-
[TestCase(@"\\a\", PathKind.Invalid)]
110-
[TestCase(@"\\a", PathKind.Invalid)]
109+
#if !LESSTHAN_NETCOREAPP20
111110
[TestCase(@":", PathKind.Invalid)]
112-
[TestCase(@"|", PathKind.Invalid)]
113-
[TestCase(@"|a", PathKind.Invalid)]
114-
[TestCase(@"a|", PathKind.Invalid)]
115-
[TestCase(@"a|a", PathKind.Invalid)]
116111
[TestCase(@":a", PathKind.Invalid)]
112+
[TestCase(@"\\a", PathKind.Invalid)]
113+
[TestCase(@"\\a\", PathKind.Invalid)]
117114
[TestCase(@"a:\:a", PathKind.Invalid)]
118115
[TestCase(@"a:\|a", PathKind.Invalid)]
119116
[TestCase(@"a\:a", PathKind.Invalid)]
120117
[TestCase(@"a\|a", PathKind.Invalid)]
118+
[TestCase(@"|", PathKind.Invalid)]
119+
[TestCase(@"|a", PathKind.Invalid)]
120+
[TestCase(@"a|", PathKind.Invalid)]
121+
[TestCase(@"a|a", PathKind.Invalid)]
122+
#endif
121123
#endif
122124
[TestCase(@"a:\\a", PathKind.Invalid)]
123125
[TestCase(@"a:\/a", PathKind.Invalid)]

CodeJam.Main/Algorithms/Algorithms.EqualRange.Comparer.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,19 @@ public static Range<int> EqualRange<TElement, TValue>(
8282
{
8383
var median = startIndex + (endIndex - startIndex) / 2;
8484
var compareResult = comparer(list[median], value);
85-
if (compareResult < 0)
86-
{
87-
startIndex = median + 1;
88-
upperBoundStartIndex = startIndex;
89-
}
90-
else if (compareResult == 0)
91-
{
92-
endIndex = median;
93-
upperBoundStartIndex = endIndex + 1;
94-
}
95-
else
96-
{
97-
endIndex = median;
98-
upperBoundEndIndex = endIndex;
85+
switch (compareResult) {
86+
case < 0:
87+
startIndex = median + 1;
88+
upperBoundStartIndex = startIndex;
89+
break;
90+
case 0:
91+
endIndex = median;
92+
upperBoundStartIndex = endIndex + 1;
93+
break;
94+
default:
95+
endIndex = median;
96+
upperBoundEndIndex = endIndex;
97+
break;
9998
}
10099
}
101100
return Range.Create(startIndex, UpperBoundCore(list, value, upperBoundStartIndex, upperBoundEndIndex, comparer));

CodeJam.Main/Algorithms/Algorithms.EqualRange.IComparable.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,19 @@ public static Range<int> EqualRange<TElement, TValue>(
8686
{
8787
var median = startIndex + (endIndex - startIndex) / 2;
8888
var compareResult = list[median].CompareTo(value);
89-
if (compareResult < 0)
90-
{
91-
startIndex = median + 1;
92-
upperBoundStartIndex = startIndex;
93-
}
94-
else if (compareResult == 0)
95-
{
96-
endIndex = median;
97-
upperBoundStartIndex = endIndex + 1;
98-
}
99-
else
100-
{
101-
endIndex = median;
102-
upperBoundEndIndex = endIndex;
89+
switch (compareResult) {
90+
case < 0:
91+
startIndex = median + 1;
92+
upperBoundStartIndex = startIndex;
93+
break;
94+
case 0:
95+
endIndex = median;
96+
upperBoundStartIndex = endIndex + 1;
97+
break;
98+
default:
99+
endIndex = median;
100+
upperBoundEndIndex = endIndex;
101+
break;
103102
}
104103
}
105104
return Range.Create(startIndex, UpperBoundCore(list, value, upperBoundStartIndex, upperBoundEndIndex));

CodeJam.Main/Arithmetic/Operators.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static partial class Operators<T>
3232
private static class CompareHelper
3333
{
3434
[NotNull, ItemNotNull]
35-
private static readonly Lazy<Func<T, T, int>> _value = new Lazy<Func<T, T, int>>(OperatorsFactory.Comparison<T>, _lazyMode);
35+
private static readonly Lazy<Func<T, T, int>> _value = new(OperatorsFactory.Comparison<T>, _lazyMode);
3636

3737
/// <summary>
3838
/// Gets a comparison function.
@@ -60,7 +60,7 @@ private static class CompareHelper
6060
private static class NaNHelper
6161
{
6262
[NotNull, ItemNotNull]
63-
private static readonly Lazy<T> _value = new Lazy<T>(OperatorsFactory.GetNaN<T>, _lazyMode);
63+
private static readonly Lazy<T> _value = new(OperatorsFactory.GetNaN<T>, _lazyMode);
6464

6565
/// <summary>
6666
/// Determines whether the type has NaN value.
@@ -93,7 +93,7 @@ private static class NaNHelper
9393
private static class NegativeInfinityHelper
9494
{
9595
[NotNull, ItemNotNull]
96-
private static readonly Lazy<T> _value = new Lazy<T>(OperatorsFactory.GetNegativeInfinity<T>, _lazyMode);
96+
private static readonly Lazy<T> _value = new(OperatorsFactory.GetNegativeInfinity<T>, _lazyMode);
9797

9898
/// <summary>
9999
/// Gets a value that determines whether the type has negative infinity value.
@@ -125,7 +125,7 @@ private static class NegativeInfinityHelper
125125
private static class PositiveInfinityHelper
126126
{
127127
[NotNull, ItemNotNull]
128-
private static readonly Lazy<T> _value = new Lazy<T>(OperatorsFactory.GetPositiveInfinity<T>, _lazyMode);
128+
private static readonly Lazy<T> _value = new(OperatorsFactory.GetPositiveInfinity<T>, _lazyMode);
129129

130130
/// <summary>
131131
/// Gets a value that determines whether the type has positive infinity value.
@@ -153,7 +153,7 @@ private static class OnesComplementHelper
153153
/// The operator factory.
154154
/// </summary>
155155
[NotNull, ItemNotNull]
156-
public static readonly Lazy<Func<T, T>> LazyValue = new Lazy<Func<T, T>>(CreateValue, _lazyMode);
156+
public static readonly Lazy<Func<T, T>> LazyValue = new(CreateValue, _lazyMode);
157157

158158
/// <summary>
159159
/// Returns the operator function.

CodeJam.Main/Arithmetic/OperatorsFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ private static TDelegate CompileOperatorCore<TDelegate>(
104104

105105
[NotNull]
106106
private static NotSupportedException FieldNotSupported([NotNull]Type type, string fieldName, Exception ex) =>
107-
new NotSupportedException($"The type {type.Name} has no field {fieldName} defined.", ex);
107+
new($"The type {type.Name} has no field {fieldName} defined.", ex);
108108

109109
[NotNull]
110110
private static NotSupportedException MethodNotSupported([NotNull] Type type, string methodName, Exception ex) =>
111-
new NotSupportedException($"The type {type.Name} has no method {methodName} defined.", ex);
111+
new($"The type {type.Name} has no method {methodName} defined.", ex);
112112

113113
[NotNull]
114114
private static NotSupportedException NotSupported<T>(ExpressionType operatorType, Exception ex) =>
115-
new NotSupportedException($"The type {typeof(T).Name} has no operator {operatorType} defined.", ex);
115+
new($"The type {typeof(T).Name} has no operator {operatorType} defined.", ex);
116116

117117
[CanBeNull]
118118
private static FieldInfo TryGetOpField<T>([NotNull] string fieldName)
@@ -199,7 +199,7 @@ public static T GetNegativeInfinity<T>()
199199
if (field == null)
200200
throw FieldNotSupported(typeof(T), nameof(double.NegativeInfinity), null);
201201

202-
return (T)field.GetValue(null);
202+
return ((T)field.GetValue(null))!;
203203
}
204204

205205
/// <summary>Determines whether the type has positive infinity value.</summary>
@@ -225,7 +225,7 @@ public static T GetPositiveInfinity<T>()
225225
if (field == null)
226226
throw FieldNotSupported(typeof(T), nameof(double.PositiveInfinity), null);
227227

228-
return (T)field.GetValue(null);
228+
return ((T)field.GetValue(null))!;
229229
}
230230
#endregion
231231

CodeJam.Main/Assertions/Code.NonDebug.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ partial class Code
2525
[DebuggerHidden, MethodImpl(AggressiveInlining)]
2626
[MustUseReturnValue]
2727
[AssertionMethod]
28-
public static ArgumentAssertion<T> Arg<T>(T arg, [InvokerParameterName] string argName) =>
29-
new ArgumentAssertion<T>(arg, argName);
28+
public static ArgumentAssertion<T> Arg<T>(T arg, [InvokerParameterName] string argName) => new(arg, argName);
3029
#endregion
3130

3231
#region DisposedIf assertions (DO NOT copy into DebugCode)

CodeJam.Main/Assertions/Code.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public static void ValidCount(
341341
[DebuggerHidden, MethodImpl(AggressiveInlining)]
342342
[AssertionMethod]
343343
public static void ValidIndex(
344-
[NonNegativeValue] int index,
344+
int index,
345345
[NotNull, InvokerParameterName] string argName)
346346
{
347347
if (index < 0)
@@ -355,7 +355,7 @@ public static void ValidIndex(
355355
[DebuggerHidden, MethodImpl(AggressiveInlining)]
356356
[AssertionMethod]
357357
public static void ValidIndex(
358-
[NonNegativeValue] int index,
358+
int index,
359359
[NotNull, InvokerParameterName] string argName,
360360
[NonNegativeValue] int length)
361361
{

CodeJam.Main/Assertions/DebugCode.generated.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// </auto-generated>
88
//------------------------------------------------------------------------------
99

10+
1011
using static CodeJam.DebugCode;
1112

1213
using System;
@@ -27,6 +28,7 @@
2728
#endif
2829

2930
using static CodeJam.Targeting.MethodImplOptionsEx;
31+
// ReSharper disable BuiltInTypeReferenceStyleForMemberAccess
3032

3133
namespace CodeJam
3234
{
@@ -351,7 +353,7 @@ public static void ValidCount(
351353
[Conditional(DebugCondition), DebuggerHidden, MethodImpl(AggressiveInlining)]
352354
[AssertionMethod]
353355
public static void ValidIndex(
354-
[NonNegativeValue] int index,
356+
int index,
355357
[NotNull, InvokerParameterName] string argName)
356358
{
357359
if (index < 0)
@@ -365,7 +367,7 @@ public static void ValidIndex(
365367
[Conditional(DebugCondition), DebuggerHidden, MethodImpl(AggressiveInlining)]
366368
[AssertionMethod]
367369
public static void ValidIndex(
368-
[NonNegativeValue] int index,
370+
int index,
369371
[NotNull, InvokerParameterName] string argName,
370372
[NonNegativeValue] int length)
371373
{

CodeJam.Main/Collections/Dictionary/DictionaryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public static TValue AddOrUpdate<TKey, TValue>(
397397
Code.NotNull(dictionary, nameof(dictionary));
398398
Code.NotNull(valueFactory, nameof(valueFactory));
399399

400-
return dictionary.AddOrUpdate(key, valueFactory, (k, oldValue) => valueFactory(k));
400+
return dictionary.AddOrUpdate(key, valueFactory, (k, _) => valueFactory(k));
401401
}
402402

403403
#endregion

CodeJam.Main/Collections/Dictionary/KeyEqualityComparer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public static class KeyEqualityComparer
2121
/// A <see cref="KeyEqualityComparer{T,TKey}"/>.
2222
/// </returns>
2323
[NotNull]
24-
public static KeyEqualityComparer<T, TKey> Create<T, TKey>([NotNull] Func<T, TKey> keySelector) =>
25-
new KeyEqualityComparer<T, TKey>(keySelector);
24+
public static KeyEqualityComparer<T, TKey> Create<T, TKey>([NotNull] Func<T, TKey> keySelector) => new(keySelector);
2625

2726
/// <summary>
2827
/// Creates a <see cref="KeyEqualityComparer{T,TKey}"/>.
@@ -38,6 +37,6 @@ public static KeyEqualityComparer<T, TKey> Create<T, TKey>([NotNull] Func<T, TKe
3837
public static KeyEqualityComparer<T, TKey> Create<T, TKey>(
3938
[NotNull] Func<T, TKey> keySelector,
4039
[CanBeNull] IEqualityComparer<TKey> comparer) =>
41-
new KeyEqualityComparer<T, TKey>(keySelector, comparer);
40+
new(keySelector, comparer);
4241
}
4342
}

0 commit comments

Comments
 (0)