Skip to content

Commit

Permalink
Merge pull request #2039 from jnyrup/PatternCombinators
Browse files Browse the repository at this point in the history
Pattern combinators
  • Loading branch information
jnyrup committed Dec 27, 2022
2 parents b396a89 + 868a20b commit 8841e12
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Common/FullFrameworkReflector.cs
Expand Up @@ -30,8 +30,7 @@ private static bool IsRelevant(Assembly ass)

private static bool IsDynamic(Assembly assembly)
{
return (assembly.GetType().FullName == "System.Reflection.Emit.AssemblyBuilder") ||
(assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder");
return assembly.GetType().FullName is "System.Reflection.Emit.AssemblyBuilder" or "System.Reflection.Emit.InternalAssemblyBuilder";
}

private static IEnumerable<Type> GetExportedTypes(Assembly assembly)
Expand Down
Expand Up @@ -12,7 +12,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon
Type expectationType = comparands.GetExpectedType(context.Options);
EqualityStrategy strategy = context.Options.GetEqualityStrategy(expectationType);

bool canHandle = (strategy == EqualityStrategy.Equals) || (strategy == EqualityStrategy.ForceEquals);
bool canHandle = strategy is EqualityStrategy.Equals or EqualityStrategy.ForceEquals;
if (canHandle)
{
context.Tracer.WriteLine(member =>
Expand Down
28 changes: 4 additions & 24 deletions Src/FluentAssertions/Extensions/FluentDateTimeExtensions.cs
Expand Up @@ -144,12 +144,12 @@ public static DateTime At(this DateTime date, TimeSpan time)
/// </summary>
public static DateTime At(this DateTime date, int hours, int minutes, int seconds = 0, int milliseconds = 0, int microseconds = 0, int nanoseconds = 0)
{
if (microseconds < 0 || microseconds > 999)
if (microseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(microseconds), "Valid values are between 0 and 999");
}

if (nanoseconds < 0 || nanoseconds > 999)
if (nanoseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(nanoseconds), "Valid values are between 0 and 999");
}
Expand All @@ -175,12 +175,12 @@ public static DateTime At(this DateTime date, int hours, int minutes, int second
/// </summary>
public static DateTimeOffset At(this DateTimeOffset date, int hours, int minutes, int seconds = 0, int milliseconds = 0, int microseconds = 0, int nanoseconds = 0)
{
if (microseconds < 0 || microseconds > 999)
if (microseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(microseconds), "Valid values are between 0 and 999");
}

if (nanoseconds < 0 || nanoseconds > 999)
if (nanoseconds is < 0 or > 999)
{
throw new ArgumentOutOfRangeException(nameof(nanoseconds), "Valid values are between 0 and 999");
}
Expand Down Expand Up @@ -257,11 +257,6 @@ public static int Nanosecond(this DateTimeOffset self)
/// </summary>
public static DateTime AddNanoseconds(this DateTime self, long nanoseconds)
{
if (nanoseconds == 0)
{
return self;
}

return self + nanoseconds.Nanoseconds();
}

Expand All @@ -270,11 +265,6 @@ public static DateTime AddNanoseconds(this DateTime self, long nanoseconds)
/// </summary>
public static DateTimeOffset AddNanoseconds(this DateTimeOffset self, long nanoseconds)
{
if (nanoseconds == 0)
{
return self;
}

return self + nanoseconds.Nanoseconds();
}

Expand All @@ -299,11 +289,6 @@ public static int Microsecond(this DateTimeOffset self)
/// </summary>
public static DateTime AddMicroseconds(this DateTime self, long microseconds)
{
if (microseconds == 0)
{
return self;
}

return self + microseconds.Microseconds();
}

Expand All @@ -312,11 +297,6 @@ public static DateTime AddMicroseconds(this DateTime self, long microseconds)
/// </summary>
public static DateTimeOffset AddMicroseconds(this DateTimeOffset self, long microseconds)
{
if (microseconds == 0)
{
return self;
}

return self + microseconds.Microseconds();
}

Expand Down
Expand Up @@ -15,7 +15,7 @@ public class DateTimeOffsetValueFormatter : IValueFormatter
/// </returns>
public bool CanHandle(object value)
{
return (value is DateTime) || (value is DateTimeOffset);
return value is DateTime or DateTimeOffset;
}

public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
Expand Down
2 changes: 1 addition & 1 deletion Tests/FluentAssertions.Specs/Common/TimeSpanExtensions.cs
Expand Up @@ -17,7 +17,7 @@ public static TimeSpan Multiply(this TimeSpan timeSpan, double factor)
// Rounding to the nearest tick is as close to the result we would have with unlimited
// precision as possible, and so likely to have the least potential to surprise.
double ticks = Math.Round(timeSpan.Ticks * factor);
if (ticks > long.MaxValue || ticks < long.MinValue)
if (ticks is > long.MaxValue or < long.MinValue)
{
throw new OverflowException("TimeSpan overflowed because the duration is too long.");
}
Expand Down

0 comments on commit 8841e12

Please sign in to comment.