}
set
{
- if (_keycomparer is CompatibleComparer)
+ if (_keycomparer is CompatibleComparer keyComparer)
{
- CompatibleComparer keyComparer = (CompatibleComparer)_keycomparer;
_keycomparer = new CompatibleComparer(value, keyComparer.Comparer);
}
else if (_keycomparer == null)
}
set
{
- if (_keycomparer is CompatibleComparer)
+ if (_keycomparer is CompatibleComparer keyComparer)
{
- CompatibleComparer keyComparer = (CompatibleComparer)_keycomparer;
_keycomparer = new CompatibleComparer(keyComparer.HashCodeProvider, value);
}
else if (_keycomparer == null)
// if the given object is a boxed Decimal and its value is equal to the
// value of this Decimal. Returns false otherwise.
//
- public override bool Equals(object? value)
- {
- if (value is decimal)
- {
- decimal other = (decimal)value;
- return DecCalc.VarDecCmp(in this, in other) == 0;
- }
- return false;
- }
+ public override bool Equals(object? value) =>
+ value is decimal other &&
+ DecCalc.VarDecCmp(in this, in other) == 0;
- public bool Equals(decimal value)
- {
- return DecCalc.VarDecCmp(in this, in value) == 0;
- }
+ public bool Equals(decimal value) =>
+ DecCalc.VarDecCmp(in this, in value) == 0;
// Returns the hash code for this Decimal.
//
{
return 1;
}
- if (value is double)
+
+ if (value is double d)
{
- double d = (double)value;
if (m_value < d) return -1;
if (m_value > d) return 1;
if (m_value == d) return 0;
else
return 1;
}
+
throw new ArgumentException(SR.Arg_MustBeDouble);
}
{
return 1;
}
- if (value is int)
+
+ // NOTE: Cannot use return (_value - value) as this causes a wrap
+ // around in cases where _value - value > MaxValue.
+ if (value is int i)
{
- // NOTE: Cannot use return (_value - value) as this causes a wrap
- // around in cases where _value - value > MaxValue.
- int i = (int)value;
if (m_value < i) return -1;
if (m_value > i) return 1;
return 0;
}
+
throw new ArgumentException(SR.Arg_MustBeInt32);
}
{
return 1;
}
- if (value is long)
+
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (value is long i)
{
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- long i = (long)value;
if (m_value < i) return -1;
if (m_value > i) return 1;
return 0;
}
+
throw new ArgumentException(SR.Arg_MustBeInt64);
}
/// <summary>Indicates whether the current Range object is equal to another object of the same type.</summary>
/// <param name="value">An object to compare with this object</param>
- public override bool Equals(object? value)
- {
- if (value is Range)
- {
- Range r = (Range)value;
- return r.Start.Equals(Start) && r.End.Equals(End);
- }
-
- return false;
- }
+ public override bool Equals(object? value) =>
+ value is Range r &&
+ r.Start.Equals(Start) &&
+ r.End.Equals(End);
/// <summary>Indicates whether the current Range object is equal to another Range object.</summary>
/// <param name="other">An object to compare with this object</param>
{
return 1;
}
- if (value is float)
+
+ if (value is float f)
{
- float f = (float)value;
if (m_value < f) return -1;
if (m_value > f) return 1;
if (m_value == f) return 0;
else // f is NaN.
return 1;
}
+
throw new ArgumentException(SR.Arg_MustBeSingle);
}
{
return 1;
}
- if (value is uint)
+
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (value is uint i)
{
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- uint i = (uint)value;
if (m_value < i) return -1;
if (m_value > i) return 1;
return 0;
}
+
throw new ArgumentException(SR.Arg_MustBeUInt32);
}
{
return 1;
}
- if (value is ulong)
+
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (value is ulong i)
{
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- ulong i = (ulong)value;
if (m_value < i) return -1;
if (m_value > i) return 1;
return 0;
}
+
throw new ArgumentException(SR.Arg_MustBeUInt64);
}