Skip to content

Commit 9d129c8

Browse files
committed
Cleanup
1 parent 1c58519 commit 9d129c8

15 files changed

+36
-31
lines changed

CodeJam.Main/Arithmetic/OperatorsFactory.cs

+1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ private static Expression BuildNullableEnumComparisonCore<T>(
387387
/// <returns>Callback for the compare operator</returns>
388388
public static Func<T?, T?, bool> ComparisonOperator<T>(ExpressionType comparisonType)
389389
{
390+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
390391
switch (comparisonType)
391392
{
392393
case ExpressionType.Equal:

CodeJam.Main/Assertions/Code.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public static T ReturnIfNotNull<T>(
263263
[InvokerParameterName] string argName)
264264
where T : class
265265
{
266-
Code.NotNull(arg, argName);
266+
NotNull(arg, argName);
267267
return arg;
268268
}
269269
#endregion

CodeJam.Main/Assertions/CodeExceptionsHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void BreakIfAttached()
3535
[DebuggerHidden, MustUseReturnValue]
3636
[StringFormatMethod("messageFormat")]
3737
public static string InvariantFormat(string messageFormat, params object[]? args) =>
38-
(args == null || args.Length == 0)
38+
args == null || args.Length == 0
3939
? messageFormat
4040
: string.Format(CultureInfo.InvariantCulture, messageFormat, args);
4141

CodeJam.Main/Collections/Enumerable/EnumerableExtensions.MinMaxOrDefault.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static T MaxOrDefault(
110110
var candidateIsNan = _hasNaN && areNotEqual(candidate, candidate);
111111

112112
// DONTTOUCH: !greaterThan used for result NaN handling
113-
if (result == null || !candidateIsNan && !greaterThan(result, candidate))
113+
if (result == null || (!candidateIsNan && !greaterThan(result, candidate)))
114114
{
115115
result = candidate;
116116
}
@@ -146,7 +146,7 @@ public static T MaxOrDefault<TSource>(
146146
var candidateIsNan = _hasNaN && areNotEqual(candidate, candidate);
147147

148148
// DONTTOUCH: !greaterThan used for result NaN handling
149-
if (result == null || !candidateIsNan && !greaterThan(result, candidate))
149+
if (result == null || (!candidateIsNan && !greaterThan(result, candidate)))
150150
{
151151
result = candidate;
152152
}

CodeJam.Main/ConnectionStrings/ConnectionStringBase.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, objec
203203
/// <inheritdoc />
204204
bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
205205
{
206-
if (_wrapper.TryGetValue(item.Key, out var value) && Equals(item.Value, value))
207-
return _wrapper.Remove(item.Key);
206+
var (key, o) = item;
207+
if (_wrapper.TryGetValue(key, out var value) && Equals(o, value))
208+
return _wrapper.Remove(key);
208209

209210
return false;
210211
}

CodeJam.Main/DisposableExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public static void DisposeAll([InstantHandle] this IEnumerable<IDisposable> disp
3535
}
3636

3737
if (exceptions != null)
38-
// ReSharper disable once UnthrowableException
3938
throw new AggregateException(exceptions);
4039
}
4140

CodeJam.Main/Expressions/ExpressionExtensions.GetMembers.cs

+7-15
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,14 @@ public static MethodInfo GetMethod(this LambdaExpression expression)
133133
{
134134
var info = GetMemberInfo(expression);
135135

136-
if (info is PropertyInfo propertyInfo)
137-
{
138-
if (propertyInfo.GetGetMethod(true) is { } getMethodInfo)
136+
return
137+
info switch
139138
{
140-
return getMethodInfo;
141-
}
142-
143-
throw CodeExceptions.Argument(nameof(expression), "Expression is not property get method.");
144-
}
145-
146-
if (info is MethodInfo methodInfo)
147-
{
148-
return methodInfo;
149-
}
150-
151-
throw CodeExceptions.Argument(nameof(expression), "Expression is not method call.");
139+
PropertyInfo propertyInfo when propertyInfo.GetGetMethod(true) is { } getMethodInfo => getMethodInfo,
140+
PropertyInfo => throw CodeExceptions.Argument(nameof(expression), "Expression is not property get method."),
141+
MethodInfo methodInfo => methodInfo,
142+
_ => throw CodeExceptions.Argument(nameof(expression), "Expression is not method call.")
143+
};
152144
}
153145

154146
/// <summary>

CodeJam.Main/Expressions/ExpressionExtensions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private static void VisitInternal(this Expression? expr, [InstantHandle] Action<
184184
{
185185
void Action(MemberBinding b)
186186
{
187+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
187188
switch (b.BindingType)
188189
{
189190
case MemberBindingType.Assignment:
@@ -497,6 +498,7 @@ private static void VisitInternal(this Expression? expr, [InstantHandle] Func<Ex
497498
{
498499
bool Modify(MemberBinding b)
499500
{
501+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
500502
switch (b.BindingType)
501503
{
502504
case MemberBindingType.Assignment:
@@ -1072,6 +1074,7 @@ private static IEnumerable<T> TransformInternal<T>(
10721074
return ex;
10731075
}
10741076

1077+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
10751078
switch (expr.NodeType)
10761079
{
10771080
case ExpressionType.Add:
@@ -1204,6 +1207,7 @@ private static IEnumerable<T> TransformInternal<T>(
12041207
{
12051208
MemberBinding Modify(MemberBinding b)
12061209
{
1210+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
12071211
switch (b.BindingType)
12081212
{
12091213
case MemberBindingType.Assignment:

CodeJam.Main/Ranges/[Ranges]/Range`2.NonGenerated.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public override int GetHashCode() =>
116116
[Pure, System.Diagnostics.Contracts.Pure]
117117
public override string ToString() =>
118118
KeyPrefixString + _key + KeySeparatorString +
119-
(IsEmpty ? EmptyString : (_from + SeparatorString + _to));
119+
(IsEmpty ? EmptyString : _from + SeparatorString + _to);
120120

121121
/// <summary>
122122
/// Returns string representation of the range using the specified format string.

CodeJam.Main/Reflection/ReflectionExtensions.MetadataAttributes.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static IEnumerable<TAttribute> GetAttributesForTypeSingleLevel<TAttribut
176176
this Type type)
177177
where TAttribute : class
178178
{
179-
var inheritanceTypes = Sequence.CreateWhileNotNull(type, t => t?.GetBaseType())
179+
var inheritanceTypes = Sequence.CreateWhileNotNull(type, t => t.GetBaseType())
180180
.ToArray();
181181

182182
// ReSharper disable once CoVariantArrayConversion
@@ -192,7 +192,7 @@ private static IEnumerable<TAttribute> GetAttributesForTypeWithNesting<TAttribut
192192
where TAttribute : class
193193
{
194194
var visited = new HashSet<Type>(_typeComparer);
195-
var typesToCheck = Sequence.CreateWhileNotNull(type, t => t?.DeclaringType);
195+
var typesToCheck = Sequence.CreateWhileNotNull(type, t => t.DeclaringType);
196196
foreach (var typeToCheck in typesToCheck)
197197
{
198198
#pragma warning disable IDE0007 // use 'var' instead of explicit type
@@ -298,7 +298,7 @@ private static MemberInfo[] GetOverrideChainCore<TMember>(
298298
var result = new List<MemberInfo>();
299299
var implMethod = accessorGetter(member);
300300
var baseDefinition = implMethod.GetBaseDefinition();
301-
var typesToCheck = Sequence.CreateWhileNotNull(implMethod.DeclaringType, t => t?.GetBaseType());
301+
var typesToCheck = Sequence.CreateWhileNotNull(implMethod.DeclaringType, t => t.GetBaseType());
302302
foreach (var type in typesToCheck)
303303
{
304304
foreach (var candidate in membersGetter(type))

CodeJam.Main/Reflection/ReflectionExtensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public static bool IsNumeric(this Type type)
224224

225225
while (true) // tail recursion expanded
226226
#if TARGETS_NET || NETSTANDARD15_OR_GREATER || TARGETS_NETCOREAPP
227+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
227228
switch (Type.GetTypeCode(type))
228229
{
229230
case TypeCode.SByte:
@@ -285,6 +286,7 @@ public static bool IsInteger(this Type type)
285286

286287
while (true) // tail recursion expanded
287288
#if TARGETS_NET || NETSTANDARD15_OR_GREATER || TARGETS_NETCOREAPP
289+
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
288290
switch (Type.GetTypeCode(type))
289291
{
290292
case TypeCode.SByte:

CodeJam.Main/Reflection/TypeAccessorT.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES. TODO: update after fixes in Theraot.Core
22
using System;
33
using System.Collections.Generic;
4-
using System.Diagnostics.CodeAnalysis;
54
using System.Linq;
65
using System.Linq.Expressions;
76
using System.Reflection;

CodeJam.Main/Strings/StringExtensions.Infix.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using JetBrains.Annotations;
77
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP
88
using StringEx = System.String;
9+
// ReSharper disable BuiltInTypeReferenceStyleForMemberAccess
910

1011
#else
1112
using StringEx = System.StringEx;

CodeJam.Main/Structures/Option/ValueOption`1.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public T Value
7979
/// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
8080
/// <param name="other">An object to compare with this object.</param>
8181
public bool Equals(ValueOption<T> other) =>
82-
!HasValue && !other.HasValue
83-
|| HasValue && other.HasValue && EqualityComparer<T>.Default.Equals(_value, other._value);
82+
(!HasValue && !other.HasValue)
83+
|| (HasValue && other.HasValue && EqualityComparer<T>.Default.Equals(_value, other._value));
8484

8585
/// <summary>Indicates whether this instance and a specified object are equal.</summary>
8686
/// <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false. </returns>

CodeJam.Main/Threading/TaskHelper.WithExtensions.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ private static Task<TResult> WaitTaskAsyncCore<TResult>(Task<TResult> task, Canc
336336
private static async Task WaitTaskAsyncImplCore(Task task, CancellationToken cancellation)
337337
{
338338
var tcs = new TaskCompletionSource<object>();
339-
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
339+
#if TARGETS_NETCOREAPP
340+
await
341+
#endif
342+
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
340343
{
341344
await (await TaskEx.WhenAny(task, tcs.Task).ConfigureAwait(false)).ConfigureAwait(false);
342345
}
@@ -346,7 +349,10 @@ private static async Task<TResult> WaitTaskAsyncImplCore<TResult>(
346349
Task<TResult> task, CancellationToken cancellation)
347350
{
348351
var tcs = new TaskCompletionSource<TResult>();
349-
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
352+
#if TARGETS_NETCOREAPP
353+
await
354+
#endif
355+
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
350356
{
351357
return await (await TaskEx.WhenAny(task, tcs.Task).ConfigureAwait(false)).ConfigureAwait(false);
352358
}

0 commit comments

Comments
 (0)