Skip to content

Commit

Permalink
Remove unused NET35 directives, further clean ups (shouldly#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwoodward authored Nov 6, 2018
1 parent aa7ebbb commit 4a7337c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 51 deletions.
25 changes: 8 additions & 17 deletions src/Shouldly/Internals/EqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Shouldly
{

/*
* Code heavily influenced by code from xunit assert equality comparer
* at https://github.com/xunit/xunit/blob/master/src/xunit2.assert/Asserts/Sdk/AssertEqualityComparer.cs
Expand Down Expand Up @@ -43,23 +42,20 @@ public bool Equals(T x, T y)

if (Numerics.IsNumericType(x) && Numerics.IsNumericType(y))
{
var tollerance = Tolerance.Empty;
return Numerics.AreEqual(x, y, ref tollerance);
var tolerance = Tolerance.Empty;
return Numerics.AreEqual(x, y, ref tolerance);
}

// Implements IEquatable<T>?
var equatable = x as IEquatable<T>;
if (equatable != null)
if (x is IEquatable<T> equatable)
return equatable.Equals(y);

// Implements IComparable<T>?
var comparableGeneric = x as IComparable<T>;
if (comparableGeneric != null)
if (x is IComparable<T> comparableGeneric)
return comparableGeneric.CompareTo(y) == 0;

// Implements IComparable?
var comparable = x as IComparable;
if (comparable != null)
if (x is IComparable comparable)
{
try
{
Expand All @@ -72,10 +68,7 @@ public bool Equals(T x, T y)
}

// Enumerable?
var enumerableX = x as IEnumerable;
var enumerableY = y as IEnumerable;

if (enumerableX != null && enumerableY != null)
if (x is IEnumerable enumerableX && y is IEnumerable enumerableY)
{
var enumeratorX = enumerableX.GetEnumerator();
var enumeratorY = enumerableY.GetEnumerator();
Expand All @@ -95,12 +88,10 @@ public bool Equals(T x, T y)
}

// Last case, rely on Object.Equals
return Object.Equals(x, y);
return object.Equals(x, y);
}

public int GetHashCode(T obj)
{
throw new NotImplementedException();
}
=> throw new NotImplementedException();
}
}
4 changes: 0 additions & 4 deletions src/Shouldly/Internals/StringHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ internal static string ToSafeString(this char c)

internal static bool IsNullOrWhiteSpace(this string s)
{
#if NET35
return string.IsNullOrEmpty(s.Trim());
#else
return string.IsNullOrWhiteSpace(s);
#endif
}

internal static string NormalizeLineEndings(this string s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public static void ShouldNotBeNullOrWhiteSpace(this string actual, string custom
public static void ShouldNotBeNullOrWhiteSpace(this string actual, [InstantHandle] Func<string> customMessage)
{
// TODO make this an extension method (str.IsNullOrWhitespace())
#if NET35
if (string.IsNullOrEmpty(actual.Trim()))
#else
if (string.IsNullOrWhiteSpace(actual))
#endif
throw new ShouldAssertException(new ExpectedShouldlyMessage(actual, customMessage).ToString());
}
}
Expand Down
26 changes: 0 additions & 26 deletions src/Shouldly/ShouldlyExtensionMethods/ShouldBeEnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,5 @@ static void CheckEnumHasFlagAttribute(Enum actual)
throw new ArgumentException("Enum doesn't have Flags attribute", nameof(actual));
}
}

#if NET35
/* If the .NET Framework doesn't have a HasFlag, patch in our own version.
Made by decompiling the HasFlag function on enum in .NET Framework version 4.5.1 */
static bool HasFlag(this Enum enumeration, Enum value)
{
if (enumeration == null)
{
return false;
}

if (value == null)
{
throw new ArgumentException(nameof(value));
}

if (!Enum.IsDefined(enumeration.GetType(), value))
{
throw new ArgumentException($"Enumeration type mismatch. The flag is of type '{value.GetType()}', was expecting {enumeration.GetType()}");
}

var longValue = Convert.ToUInt64(value);

return (Convert.ToUInt64(enumeration) & longValue) == longValue;
}
#endif
}
}

0 comments on commit 4a7337c

Please sign in to comment.