From 36cbba6b95219f532ca20df18570cf60f4bbe176 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 20 Oct 2020 10:51:38 +0200 Subject: [PATCH 1/2] Use ThrowHelper inside ValueType types --- .../src/System/ThrowHelper.cs | 6 ++++ .../src/System/ValueTuple.cs | 36 +++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs index b88eaa4d93738c..52f52d5ee7055d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -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() { diff --git a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs index f814bbb7a2c37e..bc8de601d3cd4b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs @@ -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; @@ -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; @@ -324,7 +324,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); } var objTuple = (ValueTuple)other; @@ -351,7 +351,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); } var objTuple = (ValueTuple)other; @@ -518,7 +518,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 CompareTo((ValueTuple)other); @@ -546,7 +546,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); } var objTuple = (ValueTuple)other; @@ -710,7 +710,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 CompareTo((ValueTuple)other); @@ -741,7 +741,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); } var objTuple = (ValueTuple)other; @@ -918,7 +918,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 CompareTo((ValueTuple)other); @@ -952,7 +952,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); } var objTuple = (ValueTuple)other; @@ -1144,7 +1144,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 CompareTo((ValueTuple)other); @@ -1181,7 +1181,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); } var objTuple = (ValueTuple)other; @@ -1388,7 +1388,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 CompareTo((ValueTuple)other); @@ -1428,7 +1428,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); } var objTuple = (ValueTuple)other; @@ -1650,7 +1650,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 CompareTo((ValueTuple)other); @@ -1693,7 +1693,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); } var objTuple = (ValueTuple)other; @@ -1936,7 +1936,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 CompareTo((ValueTuple)other); @@ -1982,7 +1982,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); } var objTuple = (ValueTuple)other; From a07e4e14c9559dce10ea3b90aaea94793929937d Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 20 Oct 2020 18:32:32 +0200 Subject: [PATCH 2/2] Fix formatting --- .../src/System/ValueTuple.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs index bc8de601d3cd4b..ad92422b6c8043 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs @@ -62,7 +62,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return 0; @@ -87,7 +87,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return 0; @@ -324,7 +324,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -351,7 +351,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -518,7 +518,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -546,7 +546,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -710,7 +710,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -741,7 +741,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -918,7 +918,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -952,7 +952,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -1144,7 +1144,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -1181,7 +1181,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -1388,7 +1388,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -1428,7 +1428,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -1650,7 +1650,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -1693,7 +1693,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other; @@ -1936,7 +1936,7 @@ int IComparable.CompareTo(object? other) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } return CompareTo((ValueTuple)other); @@ -1982,7 +1982,7 @@ int IStructuralComparable.CompareTo(object? other, IComparer comparer) if (!(other is ValueTuple)) { - ThrowHelper.ThrowArgumentException_TupleIncorrectType (this); + ThrowHelper.ThrowArgumentException_TupleIncorrectType(this); } var objTuple = (ValueTuple)other;