Skip to content

Use ThrowHelper inside ValueType types #43634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ internal static void ThrowArgumentException_CannotExtractScalar(ExceptionArgumen
throw GetArgumentException(ExceptionResource.Argument_CannotExtractScalar, argument);
}

[DoesNotReturn]
internal static void ThrowArgumentException_TupleIncorrectType(object obj)
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, obj.GetType()), "other");
}

[DoesNotReturn]
internal static void ThrowArgumentOutOfRange_IndexException()
{
Expand Down
36 changes: 18 additions & 18 deletions src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return 0;
Expand All @@ -87,7 +87,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return 0;
Expand Down Expand Up @@ -324,7 +324,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1>)other;
Expand All @@ -351,7 +351,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1>)other;
Expand Down Expand Up @@ -518,7 +518,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2>)other);
Expand Down Expand Up @@ -546,7 +546,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2>)other;
Expand Down Expand Up @@ -710,7 +710,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3>)other);
Expand Down Expand Up @@ -741,7 +741,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3>)other;
Expand Down Expand Up @@ -918,7 +918,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3, T4>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3, T4>)other);
Expand Down Expand Up @@ -952,7 +952,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3, T4>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3, T4>)other;
Expand Down Expand Up @@ -1144,7 +1144,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3, T4, T5>)other);
Expand Down Expand Up @@ -1181,7 +1181,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3, T4, T5>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3, T4, T5>)other;
Expand Down Expand Up @@ -1388,7 +1388,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6>)other);
Expand Down Expand Up @@ -1428,7 +1428,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6>)other;
Expand Down Expand Up @@ -1650,7 +1650,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other);
Expand Down Expand Up @@ -1693,7 +1693,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7>)other;
Expand Down Expand Up @@ -1936,7 +1936,7 @@ int IComparable.CompareTo(object? other)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

return CompareTo((ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other);
Expand Down Expand Up @@ -1982,7 +1982,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer)

if (!(other is ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>))
{
throw new ArgumentException(SR.Format(SR.ArgumentException_ValueTupleIncorrectType, GetType()), nameof(other));
ThrowHelper.ThrowArgumentException_TupleIncorrectType(this);
}

var objTuple = (ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>)other;
Expand Down