Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvk committed Jan 30, 2021
1 parent 1c58519 commit 9d129c8
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 31 deletions.
1 change: 1 addition & 0 deletions CodeJam.Main/Arithmetic/OperatorsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ private static Expression BuildNullableEnumComparisonCore<T>(
/// <returns>Callback for the compare operator</returns>
public static Func<T?, T?, bool> ComparisonOperator<T>(ExpressionType comparisonType)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (comparisonType)
{
case ExpressionType.Equal:
Expand Down
2 changes: 1 addition & 1 deletion CodeJam.Main/Assertions/Code.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static T ReturnIfNotNull<T>(
[InvokerParameterName] string argName)
where T : class
{
Code.NotNull(arg, argName);
NotNull(arg, argName);
return arg;
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion CodeJam.Main/Assertions/CodeExceptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void BreakIfAttached()
[DebuggerHidden, MustUseReturnValue]
[StringFormatMethod("messageFormat")]
public static string InvariantFormat(string messageFormat, params object[]? args) =>
(args == null || args.Length == 0)
args == null || args.Length == 0
? messageFormat
: string.Format(CultureInfo.InvariantCulture, messageFormat, args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static T MaxOrDefault(
var candidateIsNan = _hasNaN && areNotEqual(candidate, candidate);

// DONTTOUCH: !greaterThan used for result NaN handling
if (result == null || !candidateIsNan && !greaterThan(result, candidate))
if (result == null || (!candidateIsNan && !greaterThan(result, candidate)))
{
result = candidate;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public static T MaxOrDefault<TSource>(
var candidateIsNan = _hasNaN && areNotEqual(candidate, candidate);

// DONTTOUCH: !greaterThan used for result NaN handling
if (result == null || !candidateIsNan && !greaterThan(result, candidate))
if (result == null || (!candidateIsNan && !greaterThan(result, candidate)))
{
result = candidate;
}
Expand Down
5 changes: 3 additions & 2 deletions CodeJam.Main/ConnectionStrings/ConnectionStringBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, objec
/// <inheritdoc />
bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
{
if (_wrapper.TryGetValue(item.Key, out var value) && Equals(item.Value, value))
return _wrapper.Remove(item.Key);
var (key, o) = item;
if (_wrapper.TryGetValue(key, out var value) && Equals(o, value))
return _wrapper.Remove(key);

return false;
}
Expand Down
1 change: 0 additions & 1 deletion CodeJam.Main/DisposableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static void DisposeAll([InstantHandle] this IEnumerable<IDisposable> disp
}

if (exceptions != null)
// ReSharper disable once UnthrowableException
throw new AggregateException(exceptions);
}

Expand Down
22 changes: 7 additions & 15 deletions CodeJam.Main/Expressions/ExpressionExtensions.GetMembers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,14 @@ public static MethodInfo GetMethod(this LambdaExpression expression)
{
var info = GetMemberInfo(expression);

if (info is PropertyInfo propertyInfo)
{
if (propertyInfo.GetGetMethod(true) is { } getMethodInfo)
return
info switch
{
return getMethodInfo;
}

throw CodeExceptions.Argument(nameof(expression), "Expression is not property get method.");
}

if (info is MethodInfo methodInfo)
{
return methodInfo;
}

throw CodeExceptions.Argument(nameof(expression), "Expression is not method call.");
PropertyInfo propertyInfo when propertyInfo.GetGetMethod(true) is { } getMethodInfo => getMethodInfo,
PropertyInfo => throw CodeExceptions.Argument(nameof(expression), "Expression is not property get method."),
MethodInfo methodInfo => methodInfo,
_ => throw CodeExceptions.Argument(nameof(expression), "Expression is not method call.")
};
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions CodeJam.Main/Expressions/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private static void VisitInternal(this Expression? expr, [InstantHandle] Action<
{
void Action(MemberBinding b)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (b.BindingType)
{
case MemberBindingType.Assignment:
Expand Down Expand Up @@ -497,6 +498,7 @@ private static void VisitInternal(this Expression? expr, [InstantHandle] Func<Ex
{
bool Modify(MemberBinding b)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (b.BindingType)
{
case MemberBindingType.Assignment:
Expand Down Expand Up @@ -1072,6 +1074,7 @@ private static IEnumerable<T> TransformInternal<T>(
return ex;
}

// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (expr.NodeType)
{
case ExpressionType.Add:
Expand Down Expand Up @@ -1204,6 +1207,7 @@ private static IEnumerable<T> TransformInternal<T>(
{
MemberBinding Modify(MemberBinding b)
{
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (b.BindingType)
{
case MemberBindingType.Assignment:
Expand Down
2 changes: 1 addition & 1 deletion CodeJam.Main/Ranges/[Ranges]/Range`2.NonGenerated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode() =>
[Pure, System.Diagnostics.Contracts.Pure]
public override string ToString() =>
KeyPrefixString + _key + KeySeparatorString +
(IsEmpty ? EmptyString : (_from + SeparatorString + _to));
(IsEmpty ? EmptyString : _from + SeparatorString + _to);

/// <summary>
/// Returns string representation of the range using the specified format string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static IEnumerable<TAttribute> GetAttributesForTypeSingleLevel<TAttribut
this Type type)
where TAttribute : class
{
var inheritanceTypes = Sequence.CreateWhileNotNull(type, t => t?.GetBaseType())
var inheritanceTypes = Sequence.CreateWhileNotNull(type, t => t.GetBaseType())
.ToArray();

// ReSharper disable once CoVariantArrayConversion
Expand All @@ -192,7 +192,7 @@ private static IEnumerable<TAttribute> GetAttributesForTypeWithNesting<TAttribut
where TAttribute : class
{
var visited = new HashSet<Type>(_typeComparer);
var typesToCheck = Sequence.CreateWhileNotNull(type, t => t?.DeclaringType);
var typesToCheck = Sequence.CreateWhileNotNull(type, t => t.DeclaringType);
foreach (var typeToCheck in typesToCheck)
{
#pragma warning disable IDE0007 // use 'var' instead of explicit type
Expand Down Expand Up @@ -298,7 +298,7 @@ private static MemberInfo[] GetOverrideChainCore<TMember>(
var result = new List<MemberInfo>();
var implMethod = accessorGetter(member);
var baseDefinition = implMethod.GetBaseDefinition();
var typesToCheck = Sequence.CreateWhileNotNull(implMethod.DeclaringType, t => t?.GetBaseType());
var typesToCheck = Sequence.CreateWhileNotNull(implMethod.DeclaringType, t => t.GetBaseType());
foreach (var type in typesToCheck)
{
foreach (var candidate in membersGetter(type))
Expand Down
2 changes: 2 additions & 0 deletions CodeJam.Main/Reflection/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public static bool IsNumeric(this Type type)

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

while (true) // tail recursion expanded
#if TARGETS_NET || NETSTANDARD15_OR_GREATER || TARGETS_NETCOREAPP
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
switch (Type.GetTypeCode(type))
{
case TypeCode.SByte:
Expand Down
1 change: 0 additions & 1 deletion CodeJam.Main/Reflection/TypeAccessorT.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES. TODO: update after fixes in Theraot.Core
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down
1 change: 1 addition & 0 deletions CodeJam.Main/Strings/StringExtensions.Infix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using JetBrains.Annotations;
#if NET40_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP
using StringEx = System.String;
// ReSharper disable BuiltInTypeReferenceStyleForMemberAccess

#else
using StringEx = System.StringEx;
Expand Down
4 changes: 2 additions & 2 deletions CodeJam.Main/Structures/Option/ValueOption`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public T Value
/// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(ValueOption<T> other) =>
!HasValue && !other.HasValue
|| HasValue && other.HasValue && EqualityComparer<T>.Default.Equals(_value, other._value);
(!HasValue && !other.HasValue)
|| (HasValue && other.HasValue && EqualityComparer<T>.Default.Equals(_value, other._value));

/// <summary>Indicates whether this instance and a specified object are equal.</summary>
/// <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false. </returns>
Expand Down
10 changes: 8 additions & 2 deletions CodeJam.Main/Threading/TaskHelper.WithExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ private static Task<TResult> WaitTaskAsyncCore<TResult>(Task<TResult> task, Canc
private static async Task WaitTaskAsyncImplCore(Task task, CancellationToken cancellation)
{
var tcs = new TaskCompletionSource<object>();
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
#if TARGETS_NETCOREAPP
await
#endif
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
{
await (await TaskEx.WhenAny(task, tcs.Task).ConfigureAwait(false)).ConfigureAwait(false);
}
Expand All @@ -346,7 +349,10 @@ private static async Task<TResult> WaitTaskAsyncImplCore<TResult>(
Task<TResult> task, CancellationToken cancellation)
{
var tcs = new TaskCompletionSource<TResult>();
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
#if TARGETS_NETCOREAPP
await
#endif
using (cancellation.Register(() => tcs.TrySetCanceled(cancellation), false))
{
return await (await TaskEx.WhenAny(task, tcs.Task).ConfigureAwait(false)).ConfigureAwait(false);
}
Expand Down

0 comments on commit 9d129c8

Please sign in to comment.