diff --git a/src/mscorlib/model.xml b/src/mscorlib/model.xml index 3cfc360f29cc..ddd65ff773d2 100644 --- a/src/mscorlib/model.xml +++ b/src/mscorlib/model.xml @@ -9505,7 +9505,6 @@ - diff --git a/src/mscorlib/mscorlib.shared.sources.props b/src/mscorlib/mscorlib.shared.sources.props index 8721252b4d5e..46e80c77670b 100644 --- a/src/mscorlib/mscorlib.shared.sources.props +++ b/src/mscorlib/mscorlib.shared.sources.props @@ -409,7 +409,6 @@ - diff --git a/src/mscorlib/src/System/AppDomain.cs b/src/mscorlib/src/System/AppDomain.cs index abaaf4877065..a43b5d053553 100644 --- a/src/mscorlib/src/System/AppDomain.cs +++ b/src/mscorlib/src/System/AppDomain.cs @@ -2834,7 +2834,7 @@ internal static void Resume() #endif private AppDomain() { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_Constructor)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_Constructor); } [System.Security.SecuritySafeCritical] // auto-generated @@ -4559,7 +4559,7 @@ public TimeSpan MonitoringTotalProcessorTime Int64 i64ProcessorTime = nGetTotalProcessorTime(); if (i64ProcessorTime == -1) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WithoutARM); } return new TimeSpan(i64ProcessorTime); } @@ -4575,7 +4575,7 @@ public Int64 MonitoringTotalAllocatedMemorySize Int64 i64AllocatedMemory = nGetTotalAllocatedMemorySize(); if (i64AllocatedMemory == -1) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WithoutARM); } return i64AllocatedMemory; } @@ -4593,7 +4593,7 @@ public Int64 MonitoringSurvivedMemorySize Int64 i64LastSurvivedMemory = nGetLastSurvivedMemorySize(); if (i64LastSurvivedMemory == -1) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WithoutARM); } return i64LastSurvivedMemory; } @@ -4613,7 +4613,7 @@ public static Int64 MonitoringSurvivedProcessMemorySize Int64 i64LastSurvivedProcessMemory = nGetLastSurvivedProcessMemorySize(); if (i64LastSurvivedProcessMemory == -1) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WithoutARM")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_WithoutARM); } return i64LastSurvivedProcessMemory; } @@ -4630,24 +4630,24 @@ public static Int64 MonitoringSurvivedProcessMemorySize void _AppDomain.GetTypeInfoCount(out uint pcTInfo) { - throw new NotImplementedException(); + ThrowHelper.ThrowNotImplementedException(); } void _AppDomain.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo) { - throw new NotImplementedException(); + ThrowHelper.ThrowNotImplementedException(); } void _AppDomain.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId) { - throw new NotImplementedException(); + ThrowHelper.ThrowNotImplementedException(); } // If you implement this method, make sure to include _AppDomain.Invoke in VM\DangerousAPIs.h and // include _AppDomain in SystemDomain::IsReflectionInvocationMethod in AppDomain.cpp. void _AppDomain.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr) { - throw new NotImplementedException(); + ThrowHelper.ThrowNotImplementedException(); } #endif } diff --git a/src/mscorlib/src/System/Array.cs b/src/mscorlib/src/System/Array.cs index 3f175d9159c7..c42ca461bf79 100644 --- a/src/mscorlib/src/System/Array.cs +++ b/src/mscorlib/src/System/Array.cs @@ -34,7 +34,7 @@ internal Array() {} public static ReadOnlyCollection AsReadOnly(T[] array) { if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result>() != null); @@ -45,7 +45,7 @@ public static ReadOnlyCollection AsReadOnly(T[] array) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static void Resize(ref T[] array, int newSize) { if (newSize < 0) - throw new ArgumentOutOfRangeException("newSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.newSize, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Contract.ValueAtReturn(out array) != null); Contract.Ensures(Contract.ValueAtReturn(out array).Length == newSize); Contract.EndContractBlock(); @@ -68,9 +68,9 @@ public static void Resize(ref T[] array, int newSize) { public unsafe static Array CreateInstance(Type elementType, int length) { if ((object)elementType == null) - throw new ArgumentNullException("elementType"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (length < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == length); Contract.Ensures(Contract.Result().Rank == 1); @@ -78,7 +78,7 @@ public unsafe static Array CreateInstance(Type elementType, int length) RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"elementType"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); return InternalCreate((void*)t.TypeHandle.Value,1,&length,null); } @@ -86,9 +86,11 @@ public unsafe static Array CreateInstance(Type elementType, int length) public unsafe static Array CreateInstance(Type elementType, int length1, int length2) { if ((object)elementType == null) - throw new ArgumentNullException("elementType"); - if (length1 < 0 || length2 < 0) - throw new ArgumentOutOfRangeException((length1 < 0 ? "length1" : "length2"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); + if (length1 < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + if (length2 < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Rank == 2); Contract.Ensures(Contract.Result().GetLength(0) == length1); @@ -96,7 +98,7 @@ public unsafe static Array CreateInstance(Type elementType, int length1, int len RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"elementType"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); int* pLengths = stackalloc int[2]; pLengths[0] = length1; pLengths[1] = length2; @@ -107,13 +109,13 @@ public unsafe static Array CreateInstance(Type elementType, int length1, int len public unsafe static Array CreateInstance(Type elementType, int length1, int length2, int length3) { if ((object)elementType == null) - throw new ArgumentNullException("elementType"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (length1 < 0) - throw new ArgumentOutOfRangeException("length1", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (length2 < 0) - throw new ArgumentOutOfRangeException("length2", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (length3 < 0) - throw new ArgumentOutOfRangeException("length3", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length3, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Rank == 3); Contract.Ensures(Contract.Result().GetLength(0) == length1); @@ -122,7 +124,7 @@ public unsafe static Array CreateInstance(Type elementType, int length1, int len RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); int* pLengths = stackalloc int[3]; pLengths[0] = length1; pLengths[1] = length2; @@ -134,38 +136,38 @@ public unsafe static Array CreateInstance(Type elementType, int length1, int len public unsafe static Array CreateInstance(Type elementType, params int[] lengths) { if ((object)elementType == null) - throw new ArgumentNullException("elementType"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (lengths == null) - throw new ArgumentNullException("lengths"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths); if (lengths.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Rank == lengths.Length); Contract.EndContractBlock(); RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); // Check to make sure the lenghts are all positive. Note that we check this here to give // a good exception message if they are not; however we check this again inside the execution // engine's low level allocation function after having made a copy of the array to prevent a // malicious caller from mutating the array after this check. - for (int i=0;i() != null); Contract.Ensures(Contract.Result().Rank == lengths.Length); Contract.EndContractBlock(); @@ -175,8 +177,8 @@ public static Array CreateInstance(Type elementType, params long[] lengths) for (int i = 0; i < lengths.Length; ++i) { long len = lengths[i]; - if (len > Int32.MaxValue || len < Int32.MinValue) - throw new ArgumentOutOfRangeException("len", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (len > Int32.MaxValue || len < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.len, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); intLengths[i] = (int) len; } @@ -188,22 +190,22 @@ public static Array CreateInstance(Type elementType, params long[] lengths) public unsafe static Array CreateInstance(Type elementType, int[] lengths,int[] lowerBounds) { if (elementType == null) - throw new ArgumentNullException("elementType"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (lengths == null) - throw new ArgumentNullException("lengths"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths); if (lowerBounds == null) - throw new ArgumentNullException("lowerBounds"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lowerBounds); if (lengths.Length != lowerBounds.Length) - throw new ArgumentException(Environment.GetResourceString("Arg_RanksAndBounds")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RanksAndBounds); if (lengths.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_NeedAtLeast1Rank")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank); Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Rank == lengths.Length); Contract.EndContractBlock(); RuntimeType t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "elementType"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); // Check to make sure the lenghts are all positive. Note that we check this here to give // a good exception message if they are not; however we check this again inside the execution @@ -211,9 +213,9 @@ public unsafe static Array CreateInstance(Type elementType, int[] lengths,int[] // malicious caller from mutating the array after this check. for (int i=0;i= 0); @@ -313,8 +315,8 @@ public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array des [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, Array destinationArray, long length) { - if (length > Int32.MaxValue || length < Int32.MinValue) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (length > Int32.MaxValue || length < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Array.Copy(sourceArray, destinationArray, (int) length); } @@ -322,12 +324,12 @@ public static void Copy(Array sourceArray, Array destinationArray, long length) [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) { - if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) - throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue) - throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (length > Int32.MaxValue || length < Int32.MinValue) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (destinationIndex > Int32.MaxValue || destinationIndex < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destinationIndex, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (length > Int32.MaxValue || length < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Array.Copy(sourceArray, (int) sourceIndex, destinationArray, (int) destinationIndex, (int) length); } @@ -346,9 +348,9 @@ public static void Copy(Array sourceArray, long sourceIndex, Array destinationAr public unsafe Object GetValue(params int[] indices) { if (indices == null) - throw new ArgumentNullException("indices"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); if (Rank != indices.Length) - throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); @@ -361,7 +363,7 @@ public unsafe Object GetValue(params int[] indices) public unsafe Object GetValue(int index) { if (Rank != 1) - throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray); Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); @@ -373,7 +375,7 @@ public unsafe Object GetValue(int index) public unsafe Object GetValue(int index1, int index2) { if (Rank != 2) - throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray); Contract.EndContractBlock(); int* pIndices = stackalloc int[2]; @@ -389,7 +391,7 @@ public unsafe Object GetValue(int index1, int index2) public unsafe Object GetValue(int index1, int index2, int index3) { if (Rank != 3) - throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray); Contract.EndContractBlock(); int* pIndices = stackalloc int[3]; @@ -405,8 +407,8 @@ public unsafe Object GetValue(int index1, int index2, int index3) [ComVisible(false)] public Object GetValue(long index) { - if (index > Int32.MaxValue || index < Int32.MinValue) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index > Int32.MaxValue || index < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); return this.GetValue((int) index); @@ -415,10 +417,10 @@ public Object GetValue(long index) [ComVisible(false)] public Object GetValue(long index1, long index2) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); return this.GetValue((int) index1, (int) index2); @@ -427,12 +429,12 @@ public Object GetValue(long index1, long index2) [ComVisible(false)] public Object GetValue(long index1, long index2, long index3) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index3 > Int32.MaxValue || index3 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index3 > Int32.MaxValue || index3 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); return this.GetValue((int) index1, (int) index2, (int) index3); @@ -442,9 +444,9 @@ public Object GetValue(long index1, long index2, long index3) public Object GetValue(params long[] indices) { if (indices == null) - throw new ArgumentNullException("indices"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); if (Rank != indices.Length) - throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); Contract.EndContractBlock(); int[] intIndices = new int[indices.Length]; @@ -452,8 +454,8 @@ public Object GetValue(params long[] indices) for (int i = 0; i < indices.Length; ++i) { long index = indices[i]; - if (index > Int32.MaxValue || index < Int32.MinValue) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index > Int32.MaxValue || index < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); intIndices[i] = (int) index; } @@ -465,7 +467,7 @@ public Object GetValue(params long[] indices) public unsafe void SetValue(Object value,int index) { if (Rank != 1) - throw new ArgumentException(Environment.GetResourceString("Arg_Need1DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need1DArray); Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); @@ -477,7 +479,7 @@ public unsafe void SetValue(Object value,int index) public unsafe void SetValue(Object value,int index1, int index2) { if (Rank != 2) - throw new ArgumentException(Environment.GetResourceString("Arg_Need2DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray); Contract.EndContractBlock(); int* pIndices = stackalloc int[2]; @@ -493,7 +495,7 @@ public unsafe void SetValue(Object value,int index1, int index2) public unsafe void SetValue(Object value,int index1, int index2, int index3) { if (Rank != 3) - throw new ArgumentException(Environment.GetResourceString("Arg_Need3DArray")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray); Contract.EndContractBlock(); int* pIndices = stackalloc int[3]; @@ -510,9 +512,9 @@ public unsafe void SetValue(Object value,int index1, int index2, int index3) public unsafe void SetValue(Object value,params int[] indices) { if (indices == null) - throw new ArgumentNullException("indices"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); if (Rank != indices.Length) - throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); @@ -524,8 +526,8 @@ public unsafe void SetValue(Object value,params int[] indices) [ComVisible(false)] public void SetValue(Object value, long index) { - if (index > Int32.MaxValue || index < Int32.MinValue) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index > Int32.MaxValue || index < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); this.SetValue(value, (int) index); @@ -534,10 +536,10 @@ public void SetValue(Object value, long index) [ComVisible(false)] public void SetValue(Object value, long index1, long index2) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); this.SetValue(value, (int) index1, (int) index2); @@ -546,12 +548,12 @@ public void SetValue(Object value, long index1, long index2) [ComVisible(false)] public void SetValue(Object value, long index1, long index2, long index3) { - if (index1 > Int32.MaxValue || index1 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index1", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index2 > Int32.MaxValue || index2 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index2", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); - if (index3 > Int32.MaxValue || index3 < Int32.MinValue) - throw new ArgumentOutOfRangeException("index3", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index1 > Int32.MaxValue || index1 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index1, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index2 > Int32.MaxValue || index2 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index2, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); + if (index3 > Int32.MaxValue || index3 < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index3, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); this.SetValue(value, (int) index1, (int) index2, (int) index3); @@ -561,9 +563,9 @@ public void SetValue(Object value, long index1, long index2, long index3) public void SetValue(Object value, params long[] indices) { if (indices == null) - throw new ArgumentNullException("indices"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); if (Rank != indices.Length) - throw new ArgumentException(Environment.GetResourceString("Arg_RankIndices")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); Contract.EndContractBlock(); int[] intIndices = new int[indices.Length]; @@ -571,8 +573,8 @@ public void SetValue(Object value, params long[] indices) for (int i = 0; i < indices.Length; ++i) { long index = indices[i]; - if (index > Int32.MaxValue || index < Int32.MinValue) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index > Int32.MaxValue || index < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); intIndices[i] = (int) index; } @@ -693,7 +695,8 @@ Object IList.this[int index] { int IList.Add(Object value) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); + return default(int); } bool IList.Contains(Object value) @@ -713,17 +716,17 @@ int IList.IndexOf(Object value) void IList.Insert(int index, Object value) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } void IList.Remove(Object value) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } void IList.RemoveAt(int index) { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } // Make a new array which is a shallow copy of the original array. @@ -740,8 +743,9 @@ Int32 IStructuralComparable.CompareTo(Object other, IComparer comparer) { Array o = other as Array; - if (o == null || this.Length != o.Length) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_OtherNotArrayOfCorrectLength"), "other"); + if (o == null || this.Length != o.Length) + { + ThrowHelper.ThrowArgumentException(ExceptionResource.ArgumentException_OtherNotArrayOfCorrectLength, ExceptionArgument.other); } int i = 0; @@ -795,7 +799,7 @@ internal static int CombineHashCodes(int h1, int h2) { int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) { if (comparer == null) - throw new ArgumentNullException("comparer"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer); Contract.EndContractBlock(); int ret = 0; @@ -824,7 +828,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, Object value) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures((Contract.Result() >= array.GetLowerBound(0) && Contract.Result() <= array.GetUpperBound(0)) || (Contract.Result() < array.GetLowerBound(0) && ~Contract.Result() <= array.GetUpperBound(0) + 1)); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -868,7 +872,7 @@ public static int BinarySearch(Array array, int index, int length, Object value) [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, Object value, IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); return BinarySearch(array, lb, array.Length, value, comparer); @@ -894,15 +898,17 @@ public static int BinarySearch(Array array, Object value, IComparer comparer) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, int index, int length, Object value, IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); - if (index < lb || length < 0) - throw new ArgumentOutOfRangeException((index(T[] array, T value) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); return BinarySearch(array, 0, array.Length, value, null); } @@ -977,7 +983,7 @@ public static int BinarySearch(T[] array, T value) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(T[] array, T value, System.Collections.Generic.IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); return BinarySearch(array, 0, array.Length, value, comparer); } @@ -992,11 +998,14 @@ public static int BinarySearch(T[] array, int index, int length, T value) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(T[] array, int index, int length, T value, System.Collections.Generic.IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); - if (index < 0 || length < 0) - throw new ArgumentOutOfRangeException((index<0 ? "index" : "length"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + if (index < 0) + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); + if (length < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + if (array.Length - index < length) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); return ArraySortHelper.Default.BinarySearch(array, index, length, value, comparer); @@ -1004,11 +1013,11 @@ public static int BinarySearch(T[] array, int index, int length, T value, Sys public static TOutput[] ConvertAll(TInput[] array, Converter converter) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( converter == null) { - throw new ArgumentNullException("converter"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter); } Contract.Ensures(Contract.Result() != null); Contract.Ensures(Contract.Result().Length == array.Length); @@ -1032,7 +1041,7 @@ public static TOutput[] ConvertAll(TInput[] array, Converter Int32.MaxValue || index < Int32.MinValue) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_HugeArrayNotSupported")); + if (index > Int32.MaxValue || index < Int32.MinValue) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_HugeArrayNotSupported); Contract.EndContractBlock(); this.CopyTo(array, (int) index); @@ -1066,11 +1075,11 @@ public static bool Exists(T[] array, Predicate match) { public static T Find(T[] array, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); @@ -1084,11 +1093,11 @@ public static T Find(T[] array, Predicate match) { public static T[] FindAll(T[] array, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); @@ -1103,7 +1112,7 @@ public static T[] FindAll(T[] array, Predicate match) { public static int FindIndex(T[] array, Predicate match) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1113,7 +1122,7 @@ public static int FindIndex(T[] array, Predicate match) { public static int FindIndex(T[] array, int startIndex, Predicate match) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1123,19 +1132,19 @@ public static int FindIndex(T[] array, int startIndex, Predicate match) { public static int FindIndex(T[] array, int startIndex, int count, Predicate match) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( startIndex < 0 || startIndex > array.Length ) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (count < 0 || startIndex > array.Length - count) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1149,11 +1158,11 @@ public static int FindIndex(T[] array, int startIndex, int count, Predicate(T[] array, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); @@ -1167,7 +1176,7 @@ public static T FindLast(T[] array, Predicate match) { public static int FindLastIndex(T[] array, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.EndContractBlock(); @@ -1176,7 +1185,7 @@ public static int FindLastIndex(T[] array, Predicate match) { public static int FindLastIndex(T[] array, int startIndex, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.EndContractBlock(); @@ -1185,30 +1194,30 @@ public static int FindLastIndex(T[] array, int startIndex, Predicate match public static int FindLastIndex(T[] array, int startIndex, int count, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); if(array.Length == 0) { // Special case for 0 length List if( startIndex != -1) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } } else { // Make sure we're not out of range if ( startIndex < 0 || startIndex >= array.Length) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } int endIndex = startIndex - count; @@ -1222,11 +1231,11 @@ public static int FindLastIndex(T[] array, int startIndex, int count, Predica public static void ForEach(T[] array, Action action) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( action == null) { - throw new ArgumentNullException("action"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action); } Contract.EndContractBlock(); @@ -1255,7 +1264,7 @@ public IEnumerator GetEnumerator() [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -1271,7 +1280,7 @@ public static int IndexOf(Array array, Object value) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value, int startIndex) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -1288,17 +1297,17 @@ public static int IndexOf(Array array, Object value, int startIndex) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value, int startIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); if (array.Rank != 1) - throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported")); + ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); if (startIndex < lb || startIndex > array.Length + lb) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (count < 0 || count > array.Length - startIndex + lb) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); // Try calling a quick native method to handle primitive types. int retVal; @@ -1342,7 +1351,7 @@ public static int IndexOf(Array array, Object value, int startIndex, int count) [Pure] public static int IndexOf(T[] array, T value) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures((Contract.Result() < 0) || (Contract.Result() >= 0 && Contract.Result() < array.Length && EqualityComparer.Default.Equals(value, array[Contract.Result()]))); @@ -1353,7 +1362,7 @@ public static int IndexOf(T[] array, T value) { public static int IndexOf(T[] array, T value, int startIndex) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1363,15 +1372,15 @@ public static int IndexOf(T[] array, T value, int startIndex) { public static int IndexOf(T[] array, T value, int startIndex, int count) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (startIndex < 0 || startIndex > array.Length ) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (count < 0 || count > array.Length - startIndex) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1392,7 +1401,7 @@ public static int IndexOf(T[] array, T value, int startIndex, int count) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -1407,7 +1416,7 @@ public static int LastIndexOf(Array array, Object value) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value, int startIndex) { if (array == null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -1424,7 +1433,7 @@ public static int LastIndexOf(Array array, Object value, int startIndex) { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value, int startIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.Ensures(Contract.Result() < array.GetLowerBound(0) + array.Length); Contract.EndContractBlock(); int lb = array.GetLowerBound(0); @@ -1433,13 +1442,13 @@ public static int LastIndexOf(Array array, Object value, int startIndex, int cou } if (startIndex < lb || startIndex >= array.Length + lb) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); if (count > startIndex - lb + 1) - throw new ArgumentOutOfRangeException("endIndex", Environment.GetResourceString("ArgumentOutOfRange_EndIndexStartIndex")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.endIndex, ExceptionResource.ArgumentOutOfRange_EndIndexStartIndex); if (array.Rank != 1) - throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported")); + ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); // Try calling a quick native method to handle primitive types. int retVal; @@ -1478,7 +1487,7 @@ public static int LastIndexOf(Array array, Object value, int startIndex, int cou public static int LastIndexOf(T[] array, T value) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1488,7 +1497,7 @@ public static int LastIndexOf(T[] array, T value) { public static int LastIndexOf(T[] array, T value, int startIndex) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1498,7 +1507,7 @@ public static int LastIndexOf(T[] array, T value, int startIndex) { public static int LastIndexOf(T[] array, T value, int startIndex, int count) { if (array==null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } Contract.Ensures(Contract.Result() < array.Length); Contract.EndContractBlock(); @@ -1509,24 +1518,24 @@ public static int LastIndexOf(T[] array, T value, int startIndex, int count) // accept -1 and 0 as valid startIndex for compablility reason. // if( startIndex != -1 && startIndex != 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } // only 0 is a valid value for count if array is empty if( count != 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } return -1; } // Make sure we're not out of range if ( startIndex < 0 || startIndex >= array.Length) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } return EqualityComparer.Default.LastIndexOf(array, value, startIndex, count); @@ -1546,7 +1555,7 @@ public static int LastIndexOf(T[] array, T value, int startIndex, int count) [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse(Array array) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); Reverse(array, array.GetLowerBound(0), array.Length); } @@ -1561,14 +1570,17 @@ public static void Reverse(Array array) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse(Array array, int index, int length) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); int lowerBound = array.GetLowerBound(0); - if (index < lowerBound || length < 0) - throw new ArgumentOutOfRangeException((index<0 ? "index" : "length"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (index < lowerBound) + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); + if (length < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + if (array.Length - (index - lowerBound) < length) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); if (array.Rank != 1) - throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported")); + ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); Contract.EndContractBlock(); bool r = TrySZReverse(array, index, length); @@ -1610,7 +1622,7 @@ public static void Reverse(Array array, int index, int length) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); Sort(array, null, array.GetLowerBound(0), array.Length, null); } @@ -1624,7 +1636,7 @@ public static void Sort(Array array) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items) { if (keys==null) - throw new ArgumentNullException("keys"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); Contract.EndContractBlock(); Sort(keys, items, keys.GetLowerBound(0), keys.Length, null); } @@ -1658,7 +1670,7 @@ public static void Sort(Array keys, Array items, int index, int length) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array, IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); Sort(array, null, array.GetLowerBound(0), array.Length, comparer); } @@ -1674,7 +1686,7 @@ public static void Sort(Array array, IComparer comparer) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items, IComparer comparer) { if (keys==null) - throw new ArgumentNullException("keys"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); Contract.EndContractBlock(); Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer); } @@ -1702,16 +1714,19 @@ public static void Sort(Array array, int index, int length, IComparer comparer) [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items, int index, int length, IComparer comparer) { if (keys==null) - throw new ArgumentNullException("keys"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); if (keys.Rank != 1 || (items != null && items.Rank != 1)) - throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported")); + ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); int keysLowerBound = keys.GetLowerBound(0); if (items != null && keysLowerBound != items.GetLowerBound(0)) - throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch")); - if (index < keysLowerBound || length < 0) - throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_LowerBoundsMustMatch); + if (index < keysLowerBound) + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); + if (length < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + if (keys.Length - (index - keysLowerBound) < length || (items != null && (index - keysLowerBound) > items.Length - length)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); @@ -1745,7 +1760,7 @@ public static void Sort(Array keys, Array items, int index, int length, ICompare [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(T[] array) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); Sort(array, 0, array.Length, null); } @@ -1753,7 +1768,7 @@ public static void Sort(T[] array) { [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(TKey[] keys, TValue[] items) { if (keys==null) - throw new ArgumentNullException("keys"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); Contract.EndContractBlock(); Sort(keys, items, 0, keys.Length, null); } @@ -1770,8 +1785,8 @@ public static void Sort(TKey[] keys, TValue[] items, int index, in [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(T[] array, System.Collections.Generic.IComparer comparer) { - if (array==null) - throw new ArgumentNullException("array"); + if (array == null) + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); Sort(array, 0, array.Length, comparer); } @@ -1779,7 +1794,7 @@ public static void Sort(T[] array, System.Collections.Generic.IComparer co [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(TKey[] keys, TValue[] items, System.Collections.Generic.IComparer comparer) { if (keys==null) - throw new ArgumentNullException("keys"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); Contract.EndContractBlock(); Sort(keys, items, 0, keys.Length, comparer); } @@ -1788,11 +1803,13 @@ public static void Sort(TKey[] keys, TValue[] items, System.Collec [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(T[] array, int index, int length, System.Collections.Generic.IComparer comparer) { if (array==null) - throw new ArgumentNullException("array"); - if (index < 0 || length < 0) - throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + if (index < 0) + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); + if (length < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - index < length) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); if (length > 1) { @@ -1810,11 +1827,13 @@ public static void Sort(T[] array, int index, int length, System.Collections. [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(TKey[] keys, TValue[] items, int index, int length, System.Collections.Generic.IComparer comparer) { if (keys==null) - throw new ArgumentNullException("keys"); - if (index < 0 || length < 0) - throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); + if (index < 0) + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); + if (length < 0) + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (keys.Length - index < length || (items != null && index > items.Length - length)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); if (length > 1) { @@ -1836,11 +1855,11 @@ public static void Sort(TKey[] keys, TValue[] items, int index, in public static void Sort(T[] array, Comparison comparison) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( comparison == null) { - throw new ArgumentNullException("comparison"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison); } Contract.EndContractBlock(); @@ -1850,11 +1869,11 @@ public static void Sort(T[] array, Comparison comparison) { public static bool TrueForAll(T[] array, Predicate match) { if( array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if( match == null) { - throw new ArgumentNullException("match"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); @@ -1950,11 +1969,11 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (IndexOutOfRangeException) { - throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer)); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer); } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -1976,7 +1995,7 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } Object x = keys[middle]; do @@ -1990,11 +2009,11 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (IndexOutOfRangeException) { - throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer)); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer); } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } Contract.Assert(i >= left && j <= right, "(i>=left && j<=right) Sort failed - Is your IComparer bogus?"); if (i > j) break; @@ -2047,7 +2066,7 @@ private void IntrospectiveSort(int left, int length) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -2269,11 +2288,11 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (IndexOutOfRangeException) { - throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer)); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer); } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -2292,7 +2311,7 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } Object x = keys.GetValue(middle); @@ -2307,11 +2326,11 @@ private void DepthLimitedQuickSort(int left, int right, int depthLimit) } catch (IndexOutOfRangeException) { - throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer)); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer); } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } Contract.Assert(i >= left && j <= right, "(i>=left && j<=right) Sort failed - Is your IComparer bogus?"); if (i > j) break; @@ -2364,7 +2383,7 @@ private void IntrospectiveSort(int left, int length) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -2532,8 +2551,8 @@ public bool MoveNext() { public Object Current { get { - if (_index < 0) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_index >= _endIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return _array.GetValue(_index); } } @@ -2610,8 +2629,8 @@ public bool MoveNext() { public Object Current { get { - if (index < startIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_complete) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (index < startIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_complete) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return array.GetValue(_indices); } } @@ -2714,7 +2733,7 @@ internal T get_Item(int index) { //! or you may introduce a security hole! T[] _this = JitHelpers.UnsafeCast(this); if ((uint)index >= (uint)_this.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } return _this[index]; @@ -2726,7 +2745,7 @@ internal void set_Item(int index, T value) { //! or you may introduce a security hole! T[] _this = JitHelpers.UnsafeCast(this); if ((uint)index >= (uint)_this.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } _this[index] = value; @@ -2734,7 +2753,7 @@ internal void set_Item(int index, T value) { void Add(T value) { // Not meaningful for arrays. - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } [SecuritySafeCritical] @@ -2752,7 +2771,8 @@ bool get_IsReadOnly() { void Clear() { //! Warning: "this" is an array, not an SZArrayHelper. See comments above //! or you may introduce a security hole! - throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReadOnlyCollection")); + + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } [SecuritySafeCritical] @@ -2765,17 +2785,18 @@ int IndexOf(T value) { void Insert(int index, T value) { // Not meaningful for arrays - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } bool Remove(T value) { // Not meaningful for arrays - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); + return default(bool); } void RemoveAt(int index) { // Not meaningful for arrays - throw new NotSupportedException(Environment.GetResourceString("NotSupported_FixedSizeCollection")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection); } // This is a normal generic Enumerator for SZ arrays. It doesn't have any of the "this" stuff @@ -2807,8 +2828,8 @@ public bool MoveNext() { public T Current { get { - if (_index < 0) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_index >= _endIndex) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (_index < 0) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_index >= _endIndex) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return _array[_index]; } } diff --git a/src/mscorlib/src/System/ArraySegment.cs b/src/mscorlib/src/System/ArraySegment.cs index d6d26f13e5d6..49144a619bef 100644 --- a/src/mscorlib/src/System/ArraySegment.cs +++ b/src/mscorlib/src/System/ArraySegment.cs @@ -35,7 +35,7 @@ public struct ArraySegment : IList, IReadOnlyList public ArraySegment(T[] array) { if (array == null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); Contract.EndContractBlock(); _array = array; @@ -46,13 +46,13 @@ public ArraySegment(T[] array) public ArraySegment(T[] array, int offset, int count) { if (array == null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.offset, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - offset < count) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); _array = array; @@ -146,9 +146,9 @@ T IList.this[int index] get { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); if (index < 0 || index >= _count) - throw new ArgumentOutOfRangeException("index"); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); Contract.EndContractBlock(); return _array[_offset + index]; @@ -157,9 +157,9 @@ T IList.this[int index] set { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); if (index < 0 || index >= _count) - throw new ArgumentOutOfRangeException("index"); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); Contract.EndContractBlock(); _array[_offset + index] = value; @@ -169,7 +169,7 @@ T IList.this[int index] int IList.IndexOf(T item) { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); Contract.EndContractBlock(); int index = System.Array.IndexOf(_array, item, _offset, _count); @@ -182,12 +182,12 @@ int IList.IndexOf(T item) void IList.Insert(int index, T item) { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } void IList.RemoveAt(int index) { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } #endregion @@ -197,9 +197,9 @@ T IReadOnlyList.this[int index] get { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); if (index < 0 || index >= _count) - throw new ArgumentOutOfRangeException("index"); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); Contract.EndContractBlock(); return _array[_offset + index]; @@ -220,18 +220,18 @@ bool ICollection.IsReadOnly void ICollection.Add(T item) { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } void ICollection.Clear() { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } bool ICollection.Contains(T item) { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); Contract.EndContractBlock(); int index = System.Array.IndexOf(_array, item, _offset, _count); @@ -245,7 +245,7 @@ bool ICollection.Contains(T item) void ICollection.CopyTo(T[] array, int arrayIndex) { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); Contract.EndContractBlock(); System.Array.Copy(_array, _offset, array, arrayIndex, _count); @@ -253,7 +253,9 @@ void ICollection.CopyTo(T[] array, int arrayIndex) bool ICollection.Remove(T item) { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); + return default(bool); + } #endregion @@ -261,7 +263,7 @@ bool ICollection.Remove(T item) IEnumerator IEnumerable.GetEnumerator() { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); Contract.EndContractBlock(); return new ArraySegmentEnumerator(this); @@ -272,7 +274,7 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { if (_array == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullArray")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_NullArray); Contract.EndContractBlock(); return new ArraySegmentEnumerator(this); @@ -314,8 +316,8 @@ public T Current { get { - if (_current < _start) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_current >= _end) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (_current < _start) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_current >= _end) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return _array[_current]; } } diff --git a/src/mscorlib/src/System/CharEnumerator.cs b/src/mscorlib/src/System/CharEnumerator.cs index d25294c7e2ba..ea368d3e4efa 100644 --- a/src/mscorlib/src/System/CharEnumerator.cs +++ b/src/mscorlib/src/System/CharEnumerator.cs @@ -59,10 +59,8 @@ Object IEnumerator.Current { public char Current { get { - if (index == -1) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (index >= str.Length) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (index == -1) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (index >= str.Length) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return currentElement; } } diff --git a/src/mscorlib/src/System/Collections/ArrayList.cs b/src/mscorlib/src/System/Collections/ArrayList.cs index 94f4dc74e8d4..aafe099c7d56 100644 --- a/src/mscorlib/src/System/Collections/ArrayList.cs +++ b/src/mscorlib/src/System/Collections/ArrayList.cs @@ -1188,9 +1188,9 @@ public bool MoveNext() { public Object Current { get { if (_firstCall) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); if (_remaining < 0) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return _en.Current; } } @@ -2122,7 +2122,7 @@ public Object Clone() { } public bool MoveNext() { - if (version != list._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != list._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); if (index < endIndex) { currentElement = list[++index]; return true; @@ -2137,16 +2137,16 @@ public bool MoveNext() { public Object Current { get { if (index < startIndex) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); else if (index > endIndex) { - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); } return currentElement; } } public void Reset() { - if (version != list._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != list._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); index = startIndex - 1; } } @@ -2561,7 +2561,7 @@ public Object Clone() { public bool MoveNext() { if (version != list._version) { - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); } if( isArrayList) { // avoid calling virtual methods if we are operating on ArrayList to improve performance @@ -2593,10 +2593,10 @@ public Object Current { object temp = currentElement; if(dummyObject == temp) { // check if enumeration has not started or has terminated if (index == -1) { - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); } else { - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); } } @@ -2606,7 +2606,7 @@ public Object Current { public void Reset() { if (version != list._version) { - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); } currentElement = dummyObject; diff --git a/src/mscorlib/src/System/Collections/BitArray.cs b/src/mscorlib/src/System/Collections/BitArray.cs index 2f565f83af73..94ff4e7c4662 100644 --- a/src/mscorlib/src/System/Collections/BitArray.cs +++ b/src/mscorlib/src/System/Collections/BitArray.cs @@ -484,7 +484,7 @@ public Object Clone() { } public virtual bool MoveNext() { - if (version != bitarray._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != bitarray._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); if (index < (bitarray.Count-1)) { index++; currentElement = bitarray.Get(index); @@ -499,15 +499,15 @@ public virtual bool MoveNext() { public virtual Object Current { get { if (index == -1) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); if (index >= bitarray.Count) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return currentElement; } } public void Reset() { - if (version != bitarray._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != bitarray._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); index = -1; } } diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs index d805dc8be729..c704ea31f06f 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs @@ -229,7 +229,7 @@ public ConcurrentDictionary(IEqualityComparer comparer) : this(DefaultConc public ConcurrentDictionary(IEnumerable> collection, IEqualityComparer comparer) : this(comparer) { - if (collection == null) throw new ArgumentNullException("collection"); + if (collection == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); InitializeFromCollection(collection); } @@ -259,8 +259,8 @@ public ConcurrentDictionary( int concurrencyLevel, IEnumerable> collection, IEqualityComparer comparer) : this(concurrencyLevel, DEFAULT_CAPACITY, false, comparer) { - if (collection == null) throw new ArgumentNullException("collection"); - if (comparer == null) throw new ArgumentNullException("comparer"); + if (collection == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); + if (comparer == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer); InitializeFromCollection(collection); } @@ -270,11 +270,11 @@ private void InitializeFromCollection(IEnumerable> co TValue dummy; foreach (KeyValuePair pair in collection) { - if (pair.Key == null) throw new ArgumentNullException("key"); + if (pair.Key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); if (!TryAddInternal(pair.Key, pair.Value, false, false, out dummy)) { - throw new ArgumentException(GetResource("ConcurrentDictionary_SourceContainsDuplicateKeys")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_SourceContainsDuplicateKeys); } } @@ -312,13 +312,13 @@ internal ConcurrentDictionary(int concurrencyLevel, int capacity, bool growLockA { if (concurrencyLevel < 1) { - throw new ArgumentOutOfRangeException("concurrencyLevel", GetResource("ConcurrentDictionary_ConcurrencyLevelMustBePositive")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.concurrencyLevel, ExceptionResource.ConcurrentDictionary_ConcurrencyLevelMustBePositive); } if (capacity < 0) { - throw new ArgumentOutOfRangeException("capacity", GetResource("ConcurrentDictionary_CapacityMustNotBeNegative")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ConcurrentDictionary_CapacityMustNotBeNegative); } - if (comparer == null) throw new ArgumentNullException("comparer"); + if (comparer == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer); // The capacity should be at least as large as the concurrency level. Otherwise, we would have locks that don't guard // any buckets. @@ -358,7 +358,7 @@ internal ConcurrentDictionary(int concurrencyLevel, int capacity, bool growLockA /// contains too many elements. public bool TryAdd(TKey key, TValue value) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue dummy; return TryAddInternal(key, value, false, true, out dummy); } @@ -375,7 +375,7 @@ public bool TryAdd(TKey key, TValue value) /// (Nothing in Visual Basic). public bool ContainsKey(TKey key) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue throwAwayValue; return TryGetValue(key, out throwAwayValue); @@ -395,7 +395,7 @@ public bool ContainsKey(TKey key) /// (Nothing in Visual Basic). public bool TryRemove(TKey key, out TValue value) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); return TryRemoveInternal(key, out value, false, default(TValue)); } @@ -486,7 +486,7 @@ private bool TryRemoveInternal(TKey key, out TValue value, bool matchValue, TVal [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")] public bool TryGetValue(TKey key, out TValue value) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); int bucketNo, lockNoUnused; @@ -531,7 +531,7 @@ public bool TryGetValue(TKey key, out TValue value) [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")] public bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); IEqualityComparer valueComparer = EqualityComparer.Default; @@ -642,8 +642,8 @@ public void Clear() [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "ConcurrencyCop just doesn't know about these locks")] void ICollection>.CopyTo(KeyValuePair[] array, int index) { - if (array == null) throw new ArgumentNullException("array"); - if (index < 0) throw new ArgumentOutOfRangeException("index", GetResource("ConcurrentDictionary_IndexIsNegative")); + if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + if (index < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ConcurrentDictionary_IndexIsNegative); int locksAcquired = 0; try @@ -659,7 +659,7 @@ void ICollection>.CopyTo(KeyValuePair[] if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow { - throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayNotLargeEnough")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayNotLargeEnough); } CopyToPairs(array, index); @@ -956,13 +956,13 @@ public TValue this[TKey key] TValue value; if (!TryGetValue(key, out value)) { - throw new KeyNotFoundException(); + ThrowHelper.ThrowKeyNotFoundException(); } return value; } set { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue dummy; TryAddInternal(key, value, true, true, out dummy); } @@ -1026,8 +1026,8 @@ public int Count /// if the key was not in the dictionary. public TValue GetOrAdd(TKey key, Func valueFactory) { - if (key == null) throw new ArgumentNullException("key"); - if (valueFactory == null) throw new ArgumentNullException("valueFactory"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); + if (valueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.valueFactory); TValue resultingValue; if (TryGetValue(key, out resultingValue)) @@ -1052,7 +1052,7 @@ public TValue GetOrAdd(TKey key, Func valueFactory) /// key is already in the dictionary, or the new value if the key was not in the dictionary. public TValue GetOrAdd(TKey key, TValue value) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue resultingValue; TryAddInternal(key, value, false, true, out resultingValue); @@ -1080,9 +1080,9 @@ public TValue GetOrAdd(TKey key, TValue value) /// absent) or the result of updateValueFactory (if the key was present). public TValue AddOrUpdate(TKey key, Func addValueFactory, Func updateValueFactory) { - if (key == null) throw new ArgumentNullException("key"); - if (addValueFactory == null) throw new ArgumentNullException("addValueFactory"); - if (updateValueFactory == null) throw new ArgumentNullException("updateValueFactory"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); + if (addValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.addValueFactory); + if (updateValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.updateValueFactory); TValue newValue, resultingValue; while (true) @@ -1127,8 +1127,8 @@ public TValue AddOrUpdate(TKey key, Func addValueFactory, Func public TValue AddOrUpdate(TKey key, TValue addValue, Func updateValueFactory) { - if (key == null) throw new ArgumentNullException("key"); - if (updateValueFactory == null) throw new ArgumentNullException("updateValueFactory"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); + if (updateValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.updateValueFactory); TValue newValue, resultingValue; while (true) { @@ -1207,7 +1207,7 @@ void IDictionary.Add(TKey key, TValue value) { if (!TryAdd(key, value)) { - throw new ArgumentException(GetResource("ConcurrentDictionary_KeyAlreadyExisted")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_KeyAlreadyExisted); } } @@ -1340,8 +1340,7 @@ bool ICollection>.IsReadOnly /// name="keyValuePair"/> is a null reference (Nothing in Visual Basic). bool ICollection>.Remove(KeyValuePair keyValuePair) { - if (keyValuePair.Key == null) throw new ArgumentNullException(GetResource("ConcurrentDictionary_ItemKeyIsNull")); - + if (keyValuePair.Key == null) ThrowHelper.ThrowArgumentNullException(ExceptionResource.ConcurrentDictionary_ItemKeyIsNull); TValue throwAwayValue; return TryRemoveInternal(keyValuePair.Key, out throwAwayValue, true, keyValuePair.Value); } @@ -1387,17 +1386,17 @@ IEnumerator IEnumerable.GetEnumerator() /// void IDictionary.Add(object key, object value) { - if (key == null) throw new ArgumentNullException("key"); - if (!(key is TKey)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfKeyIncorrect")); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); + if (!(key is TKey)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfKeyIncorrect); - TValue typedValue; + TValue typedValue = default(TValue); try { typedValue = (TValue)value; } catch (InvalidCastException) { - throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfValueIncorrect")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfValueIncorrect); } ((IDictionary)this).Add((TKey)key, typedValue); @@ -1415,7 +1414,7 @@ void IDictionary.Add(object key, object value) /// (Nothing in Visual Basic). bool IDictionary.Contains(object key) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); return (key is TKey) && ((ConcurrentDictionary)this).ContainsKey((TKey)key); } @@ -1475,7 +1474,7 @@ ICollection IDictionary.Keys /// (Nothing in Visual Basic). void IDictionary.Remove(object key) { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue throwAwayValue; if (key is TKey) @@ -1517,7 +1516,7 @@ object IDictionary.this[object key] { get { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); TValue value; if (key is TKey && this.TryGetValue((TKey)key, out value)) @@ -1529,10 +1528,10 @@ object IDictionary.this[object key] } set { - if (key == null) throw new ArgumentNullException("key"); + if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); - if (!(key is TKey)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfKeyIncorrect")); - if (!(value is TValue)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfValueIncorrect")); + if (!(key is TKey)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfKeyIncorrect); + if (!(value is TValue)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfValueIncorrect); ((ConcurrentDictionary)this)[(TKey)key] = (TValue)value; } @@ -1563,8 +1562,8 @@ object IDictionary.this[object key] [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "ConcurrencyCop just doesn't know about these locks")] void ICollection.CopyTo(Array array, int index) { - if (array == null) throw new ArgumentNullException("array"); - if (index < 0) throw new ArgumentOutOfRangeException("index", GetResource("ConcurrentDictionary_IndexIsNegative")); + if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); + if (index < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ConcurrentDictionary_IndexIsNegative); int locksAcquired = 0; try @@ -1581,7 +1580,7 @@ void ICollection.CopyTo(Array array, int index) if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow { - throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayNotLargeEnough")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayNotLargeEnough); } // To be consistent with the behavior of ICollection.CopyTo() in Dictionary, @@ -1611,7 +1610,7 @@ void ICollection.CopyTo(Array array, int index) return; } - throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayIncorrectType"), "array"); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayIncorrectType, ExceptionArgument.array); } finally { @@ -1641,7 +1640,8 @@ object ICollection.SyncRoot { get { - throw new NotSupportedException(Environment.GetResourceString("ConcurrentCollection_SyncRoot_NotSupported")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); + return default(object); } } @@ -1976,18 +1976,6 @@ private void Assert(bool condition) Contract.Assert(condition); } - /// - /// A helper function to obtain the string for a particular resource key. - /// - /// - /// - private string GetResource(string key) - { - Assert(key != null); - - return Environment.GetResourceString(key); - } - /// /// A node in a singly-linked list representing a particular hash table bucket. /// diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs index 9164eadad10d..a60278dd8325 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs @@ -103,7 +103,7 @@ public ConcurrentQueue(IEnumerable collection) { if (collection == null) { - throw new ArgumentNullException("collection"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } InitializeFromCollection(collection); @@ -160,7 +160,7 @@ void ICollection.CopyTo(Array array, int index) // Validate arguments. if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -196,7 +196,8 @@ object ICollection.SyncRoot { get { - throw new NotSupportedException(Environment.GetResourceString("ConcurrentCollection_SyncRoot_NotSupported")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); + return default(object); } } @@ -441,7 +442,7 @@ public void CopyTo(T[] array, int index) { if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } // We must be careful not to corrupt the array, so we will first accumulate an diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs index 15d4176cffdc..35426778cbef 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs @@ -101,7 +101,7 @@ public ConcurrentStack(IEnumerable collection) { if (collection == null) { - throw new ArgumentNullException("collection"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } InitializeFromCollection(collection); } @@ -247,7 +247,8 @@ object ICollection.SyncRoot { get { - throw new NotSupportedException(Environment.GetResourceString("ConcurrentCollection_SyncRoot_NotSupported")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); + return default(object); } } @@ -293,7 +294,7 @@ void ICollection.CopyTo(Array array, int index) // Validate arguments. if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -327,7 +328,7 @@ public void CopyTo(T[] array, int index) { if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -379,7 +380,7 @@ public void PushRange(T[] items) { if (items == null) { - throw new ArgumentNullException("items"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.items); } PushRange(items, 0, items.Length); } @@ -471,20 +472,20 @@ private void ValidatePushPopRangeInput(T[] items, int startIndex, int count) { if (items == null) { - throw new ArgumentNullException("items"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.items); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ConcurrentStack_PushPopRange_CountOutOfRange")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ConcurrentStack_PushPopRange_CountOutOfRange); } int length = items.Length; if (startIndex >= length || startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ConcurrentStack_PushPopRange_StartOutOfRange")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ConcurrentStack_PushPopRange_StartOutOfRange); } if (length - count < startIndex) //instead of (startIndex + count > items.Length) to prevent overflow { - throw new ArgumentException(Environment.GetResourceString("ConcurrentStack_PushPopRange_InvalidCount")); + ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentStack_PushPopRange_InvalidCount); } } @@ -584,7 +585,7 @@ public int TryPopRange(T[] items) { if (items == null) { - throw new ArgumentNullException("items"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.items); } return TryPopRange(items, 0, items.Length); diff --git a/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs b/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs index 02263b7f97dc..14a028caec83 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs @@ -129,7 +129,8 @@ protected OrderablePartitioner(bool keysOrderedInEachPartition, bool keysOrdered /// partitioner. public virtual IEnumerable> GetOrderableDynamicPartitions() { - throw new NotSupportedException(Environment.GetResourceString("Partitioner_DynamicPartitionsNotSupported")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.Partitioner_DynamicPartitionsNotSupported); + return default(IEnumerable>); } /// @@ -172,7 +173,7 @@ public override IList> GetPartitions(int partitionCount) if (orderablePartitions.Count != partitionCount) { - throw new InvalidOperationException("OrderablePartitioner_GetPartitions_WrongNumberOfPartitions"); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.OrderablePartitioner_GetPartitions_WrongNumberOfPartitions); } IEnumerator[] partitions = new IEnumerator[partitionCount]; diff --git a/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs b/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs index 3d54c1471b41..1449773e9a2b 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs @@ -96,7 +96,8 @@ public virtual bool SupportsDynamicPartitions /// partitioner. public virtual IEnumerable GetDynamicPartitions() { - throw new NotSupportedException(Environment.GetResourceString("Partitioner_DynamicPartitionsNotSupported")); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.Partitioner_DynamicPartitionsNotSupported); + return default(IEnumerable); } } } diff --git a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs index 2169c6dee749..cdc821abe384 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs @@ -91,7 +91,7 @@ public static OrderablePartitioner Create(IList list, { if (list == null) { - throw new ArgumentNullException("list"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); } if (loadBalance) { @@ -122,7 +122,7 @@ public static OrderablePartitioner Create(TSource[] array, boo if (array == null) { - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (loadBalance) { @@ -172,11 +172,11 @@ public static OrderablePartitioner Create(IEnumerable { if (source == null) { - throw new ArgumentNullException("source"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } if ((partitionerOptions & (~EnumerablePartitionerOptions.NoBuffering)) != 0) - throw new ArgumentOutOfRangeException("partitionerOptions"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.partitionerOptions); return (new DynamicPartitionerForIEnumerable(source, partitionerOptions)); } @@ -194,7 +194,7 @@ public static OrderablePartitioner> Create(long fromInclusive, // load balancing on a busy system if you make it higher than 1. int coreOversubscriptionRate = 3; - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); + if (toExclusive <= fromInclusive) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.toExclusive); long rangeSize = (toExclusive - fromInclusive) / (PlatformHelper.ProcessorCount * coreOversubscriptionRate); if (rangeSize == 0) rangeSize = 1; @@ -212,8 +212,8 @@ public static OrderablePartitioner> Create(long fromInclusive, /// less than or equal to 0. public static OrderablePartitioner> Create(long fromInclusive, long toExclusive, long rangeSize) { - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); - if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize"); + if (toExclusive <= fromInclusive) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.toExclusive); + if (rangeSize <= 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.rangeSize); return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time } @@ -251,7 +251,7 @@ public static OrderablePartitioner> Create(int fromInclusive, in // load balancing on a busy system if you make it higher than 1. int coreOversubscriptionRate = 3; - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); + if (toExclusive <= fromInclusive) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.toExclusive); int rangeSize = (toExclusive - fromInclusive) / (PlatformHelper.ProcessorCount * coreOversubscriptionRate); if (rangeSize == 0) rangeSize = 1; @@ -269,8 +269,8 @@ public static OrderablePartitioner> Create(int fromInclusive, in /// less than or equal to 0. public static OrderablePartitioner> Create(int fromInclusive, int toExclusive, int rangeSize) { - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); - if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize"); + if (toExclusive <= fromInclusive) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.toExclusive); + if (rangeSize <= 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.rangeSize); return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time } @@ -401,7 +401,7 @@ protected DynamicPartitionEnumerator_Abstract(TSourceReader sharedReader, Shared /// public void Reset() { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } @@ -517,7 +517,7 @@ override public IList>> GetOrderablePart { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.partitionCount); } IEnumerator>[] partitions = new IEnumerator>[partitionCount]; @@ -622,13 +622,10 @@ public IEnumerator> GetEnumerator() { if (m_disposed) { - throw new ObjectDisposedException(Environment.GetResourceString("PartitionerStatic_CanNotCallGetEnumeratorAfterSourceHasBeenDisposed")); - } - else - { - return new InternalPartitionEnumerator(m_sharedReader, m_sharedIndex, - m_hasNoElementsLeft, m_sharedLock, m_activePartitionCount, this, m_useSingleChunking); + ThrowHelper.ThrowObjectDisposedException(ExceptionResource.PartitionerStatic_CanNotCallGetEnumeratorAfterSourceHasBeenDisposed); } + return new InternalPartitionEnumerator(m_sharedReader, m_sharedIndex, + m_hasNoElementsLeft, m_sharedLock, m_activePartitionCount, this, m_useSingleChunking); } @@ -986,7 +983,7 @@ override public KeyValuePair Current //verify that MoveNext is at least called once before Current is called if (m_currentChunkSize == null) { - throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.PartitionerStatic_CurrentCalledBeforeMoveNext); } Contract.Assert(m_localList != null); Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value); @@ -1053,7 +1050,7 @@ override public IList>> GetOrderablePart { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.partitionCount); } IEnumerator>[] partitions = new IEnumerator>[partitionCount]; @@ -1265,7 +1262,7 @@ override public KeyValuePair Current //verify that MoveNext is at least called once before Current is called if (m_currentChunkSize == null) { - throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.PartitionerStatic_CurrentCalledBeforeMoveNext); } Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value); @@ -1349,7 +1346,7 @@ override public KeyValuePair Current //verify that MoveNext is at least called once before Current is called if (m_currentChunkSize == null) { - throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.PartitionerStatic_CurrentCalledBeforeMoveNext); } Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value); @@ -1417,7 +1414,7 @@ override public IList>> GetOrderablePart { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.partitionCount); } int quotient, remainder; @@ -1489,7 +1486,7 @@ public void Dispose() public void Reset() { - throw new NotSupportedException(); + ThrowHelper.ThrowNotSupportedException(); } /// @@ -1576,7 +1573,7 @@ override public KeyValuePair Current //verify that MoveNext is at least called once before Current is called if (m_offset < m_startIndex) { - throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.PartitionerStatic_CurrentCalledBeforeMoveNext); } Contract.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex); @@ -1633,7 +1630,7 @@ override public KeyValuePair Current //verify that MoveNext is at least called once before Current is called if (m_offset < m_startIndex) { - throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.PartitionerStatic_CurrentCalledBeforeMoveNext); } Contract.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex); diff --git a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs index b2fed9d78fb9..52038e6b2a9d 100644 --- a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs @@ -57,7 +57,7 @@ internal static void ThrowOrIgnoreBadComparer(Object comparer) { // an app compat persective, we're changing to never throw on v4. Instead, we'll return with a partially // sorted array. if(BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) { - throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer)); + ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_BogusIComparer, ExceptionArgument.comparer); } } @@ -134,7 +134,7 @@ public void Sort(T[] keys, int index, int length, IComparer comparer) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -151,7 +151,8 @@ public int BinarySearch(T[] array, int index, int length, T value, IComparer } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); + return default(int); } } @@ -490,7 +491,7 @@ public void Sort(T[] keys, int index, int length, IComparer comparer) } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -512,7 +513,8 @@ public int BinarySearch(T[] array, int index, int length, T value, IComparer } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); + return default(int); } } @@ -902,7 +904,7 @@ public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer< } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } @@ -1253,7 +1255,7 @@ public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer< } catch (Exception e) { - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_IComparerFailed, e); } } diff --git a/src/mscorlib/src/System/Collections/Generic/Comparer.cs b/src/mscorlib/src/System/Collections/Generic/Comparer.cs index 9f1a8bff6f9b..853907bb370b 100644 --- a/src/mscorlib/src/System/Collections/Generic/Comparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/Comparer.cs @@ -33,7 +33,7 @@ public static Comparer Create(Comparison comparison) Contract.Ensures(Contract.Result>() != null); if (comparison == null) - throw new ArgumentNullException("comparison"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison); return new ComparisonComparer(comparison); } diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs index 9cbfff5a5708..3c7b9b56118f 100644 --- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs @@ -263,7 +263,7 @@ private void CopyTo(KeyValuePair[] array, int index) { } if (index < 0 || index > array.Length ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -557,7 +557,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { @@ -837,7 +837,7 @@ public void CopyTo(TKey[] array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -898,7 +898,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -1024,7 +1024,7 @@ public void CopyTo(TValue[] array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) { @@ -1085,7 +1085,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < dictionary.Count) diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index b845d64fedf3..d721c2863f94 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -355,13 +355,13 @@ public override int GetHashCode(byte b) { [System.Security.SecuritySafeCritical] // auto-generated internal unsafe override int IndexOf(byte[] array, byte value, int startIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); if (count > array.Length - startIndex) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); + ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); Contract.EndContractBlock(); if (count == 0) return -1; fixed (byte* pbytes = array) { diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs index 6e954c03ed7b..2b576b72113c 100644 --- a/src/mscorlib/src/System/Collections/Generic/List.cs +++ b/src/mscorlib/src/System/Collections/Generic/List.cs @@ -174,7 +174,7 @@ public T this[int index] { get { // Following trick can reduce the range check by one if ((uint) index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } Contract.EndContractBlock(); return _items[index]; @@ -182,7 +182,7 @@ public T this[int index] { set { if ((uint) index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } Contract.EndContractBlock(); _items[index] = value; @@ -274,7 +274,7 @@ public ReadOnlyCollection AsReadOnly() { // public int BinarySearch(int index, int count, T item, IComparer comparer) { if (index < 0) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (count < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); if (_size - index < count) @@ -575,7 +575,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { public List GetRange(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -628,7 +628,7 @@ int System.Collections.IList.IndexOf(Object item) // public int IndexOf(T item, int index) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(Contract.Result() < Count); Contract.EndContractBlock(); @@ -646,7 +646,7 @@ public int IndexOf(T item, int index) { // public int IndexOf(T item, int index, int count) { if (index > _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); if (count <0 || index > _size - count) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); Contract.Ensures(Contract.Result() >= -1); @@ -698,7 +698,7 @@ public void InsertRange(int index, IEnumerable collection) { } if ((uint)index > (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } Contract.EndContractBlock(); @@ -768,7 +768,7 @@ public int LastIndexOf(T item) public int LastIndexOf(T item, int index) { if (index >= _size) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); Contract.Ensures(Contract.Result() >= -1); Contract.Ensures(((Count == 0) && (Contract.Result() == -1)) || ((Count > 0) && (Contract.Result() <= index))); Contract.EndContractBlock(); @@ -786,7 +786,7 @@ public int LastIndexOf(T item, int index) // public int LastIndexOf(T item, int index, int count) { if ((Count != 0) && (index < 0)) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if ((Count !=0) && (count < 0)) { @@ -870,7 +870,7 @@ public int RemoveAll(Predicate match) { // public void RemoveAt(int index) { if ((uint)index >= (uint)_size) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } Contract.EndContractBlock(); _size--; @@ -885,7 +885,7 @@ public void RemoveAt(int index) { // public void RemoveRange(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -919,7 +919,7 @@ public void Reverse() { // public void Reverse(int index, int count) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { @@ -973,7 +973,7 @@ public void Sort(IComparer comparer) // public void Sort(int index, int count, IComparer comparer) { if (index < 0) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (count < 0) { diff --git a/src/mscorlib/src/System/Collections/Hashtable.cs b/src/mscorlib/src/System/Collections/Hashtable.cs index 262ccedea6cc..35f670940a96 100644 --- a/src/mscorlib/src/System/Collections/Hashtable.cs +++ b/src/mscorlib/src/System/Collections/Hashtable.cs @@ -1196,7 +1196,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte // Explicitly check to see if anyone changed the Hashtable while we // were serializing it. That's a race condition in their code. if (version != oldVersion) - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); } } @@ -1566,13 +1566,13 @@ public Object Clone() { public virtual Object Key { get { - if (current == false) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + if (current == false) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); return currentKey; } } public virtual bool MoveNext() { - if (version != hashtable.version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != hashtable.version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); while (bucket > 0) { bucket--; Object keyv = hashtable.buckets[bucket].key; @@ -1589,7 +1589,7 @@ public virtual bool MoveNext() { public virtual DictionaryEntry Entry { get { - if (current == false) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumOpCantHappen)); + if (current == false) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); return new DictionaryEntry(currentKey, currentValue); } } @@ -1597,7 +1597,7 @@ public virtual DictionaryEntry Entry { public virtual Object Current { get { - if (current == false) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumOpCantHappen)); + if (current == false) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); if (getObjectRetType==Keys) return currentKey; @@ -1610,13 +1610,13 @@ public virtual Object Current { public virtual Object Value { get { - if (current == false) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumOpCantHappen)); + if (current == false) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumOpCantHappen); return currentValue; } } public virtual void Reset() { - if (version != hashtable.version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != hashtable.version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); current = false; bucket = hashtable.buckets.Length; currentKey = null; diff --git a/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs b/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs index b9ed1a15f98a..39299494f8b3 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/Collection.cs @@ -49,7 +49,7 @@ public T this[int index] { } if (index < 0 || index >= items.Count) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } SetItem(index, value); @@ -118,7 +118,7 @@ public void RemoveAt(int index) { } if (index < 0 || index >= items.Count) { - ThrowHelper.ThrowArgumentOutOfRangeException(); + ThrowHelper.ThrowIndexArgumentOutOfRange_IndexException(); } RemoveItem(index); @@ -183,7 +183,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 ) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { diff --git a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 11833c2c1b10..98a1d5ad29f4 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -34,7 +34,7 @@ public class ReadOnlyDictionary : IDictionary, IDict public ReadOnlyDictionary(IDictionary dictionary) { if (dictionary == null) { - throw new ArgumentNullException("dictionary"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary); } Contract.EndContractBlock(); m_dictionary = dictionary; @@ -240,7 +240,7 @@ void ICollection.CopyTo(Array array, int index) { } if (index < 0 || index > array.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); + ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } if (array.Length - index < Count) { diff --git a/src/mscorlib/src/System/Collections/SortedList.cs b/src/mscorlib/src/System/Collections/SortedList.cs index 8e3926af0102..c3e2d845a4fa 100644 --- a/src/mscorlib/src/System/Collections/SortedList.cs +++ b/src/mscorlib/src/System/Collections/SortedList.cs @@ -803,14 +803,14 @@ public virtual Object Current { public virtual Object Value { get { - if (version != sortedList.version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != sortedList.version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); if (current == false) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumOpCantHappen")); return value; } } public virtual void Reset() { - if (version != sortedList.version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (version != sortedList.version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); index = startIndex; current = false; key = null; @@ -848,12 +848,12 @@ public virtual Object SyncRoot { } public virtual int Add(Object key) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); - // return 0; // suppress compiler warning + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); + return default(int); } public virtual void Clear() { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual bool Contains(Object key) { @@ -870,7 +870,7 @@ public virtual void CopyTo(Array array, int arrayIndex) { } public virtual void Insert(int index, Object value) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual Object this[int index] { @@ -898,11 +898,11 @@ public virtual int IndexOf(Object key) { } public virtual void Remove(Object key) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual void RemoveAt(int index) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } } @@ -936,11 +936,12 @@ public virtual Object SyncRoot { } public virtual int Add(Object key) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); + return default(int); } public virtual void Clear() { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual bool Contains(Object value) { @@ -957,7 +958,7 @@ public virtual void CopyTo(Array array, int arrayIndex) { } public virtual void Insert(int index, Object value) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual Object this[int index] { @@ -965,7 +966,7 @@ public virtual Object this[int index] { return sortedList.GetByIndex(index); } set { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } } @@ -978,11 +979,11 @@ public virtual int IndexOf(Object value) { } public virtual void Remove(Object value) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } public virtual void RemoveAt(int index) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_SortedListNestedWrite)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_SortedListNestedWrite); } } diff --git a/src/mscorlib/src/System/Collections/Stack.cs b/src/mscorlib/src/System/Collections/Stack.cs index 0384a4ee812a..270bed7d90ee 100644 --- a/src/mscorlib/src/System/Collections/Stack.cs +++ b/src/mscorlib/src/System/Collections/Stack.cs @@ -323,7 +323,7 @@ public Object Clone() public virtual bool MoveNext() { bool retval; - if (_version != _stack._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (_version != _stack._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); if (_index == -2) { // First call to enumerator. _index = _stack._size-1; retval = ( _index >= 0); @@ -345,14 +345,14 @@ public virtual bool MoveNext() { public virtual Object Current { get { - if (_index == -2) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_index == -1) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (_index == -2) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_index == -1) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return currentElement; } } public virtual void Reset() { - if (_version != _stack._version) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumFailedVersion)); + if (_version != _stack._version) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); _index = -2; currentElement = null; } diff --git a/src/mscorlib/src/System/Convert.cs b/src/mscorlib/src/System/Convert.cs index d1468314f271..dce9fe6a1013 100644 --- a/src/mscorlib/src/System/Convert.cs +++ b/src/mscorlib/src/System/Convert.cs @@ -579,7 +579,7 @@ public static char ToChar(String value, IFormatProvider provider) { Contract.EndContractBlock(); if (value.Length != 1) - throw new FormatException(Environment.GetResourceString(ResId.Format_NeedSingleChar)); + ThrowHelper.ThrowFormatException(ExceptionResource.Format_NeedSingleChar); return value[0]; } diff --git a/src/mscorlib/src/System/Internal.cs b/src/mscorlib/src/System/Internal.cs index 8c9701d90391..c6be49f83f0e 100644 --- a/src/mscorlib/src/System/Internal.cs +++ b/src/mscorlib/src/System/Internal.cs @@ -47,6 +47,11 @@ static class Internal // This can be removed after V2, when we implement other schemes // of keeping the JIT-compiler out for generic instantiations. + // Method marked as NoOptimization as we don't want the JIT to + // inline any methods or take any short-circuit paths since the + // instantiation closure process is driven by "fixup" references + // left in the final code stream. + [MethodImplAttribute(MethodImplOptions.NoOptimization)] static void CommonlyUsedGenericInstantiations() { // Make absolutely sure we include some of the most common @@ -54,10 +59,11 @@ static void CommonlyUsedGenericInstantiations() // Note that reference type instantiations are already included // automatically for us. - System.Array.Sort(null); - System.Array.Sort(null); - System.Array.Sort(null); - + // Need to sort non null, len > 1 array or paths will short-circuit + Array.Sort(new double[1]); + Array.Sort(new int[1]); + Array.Sort(new IntPtr[1]); + new ArraySegment(new byte[1], 0, 0); new Dictionary(); diff --git a/src/mscorlib/src/System/Lazy.cs b/src/mscorlib/src/System/Lazy.cs index 883979ef5616..3099803cd2b1 100644 --- a/src/mscorlib/src/System/Lazy.cs +++ b/src/mscorlib/src/System/Lazy.cs @@ -207,7 +207,7 @@ public Lazy(Func valueFactory, bool isThreadSafe) public Lazy(Func valueFactory, LazyThreadSafetyMode mode) { if (valueFactory == null) - throw new ArgumentNullException("valueFactory"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.valueFactory); m_threadSafeObj = GetObjectFromMode(mode); m_valueFactory = valueFactory; @@ -223,7 +223,7 @@ private static object GetObjectFromMode(LazyThreadSafetyMode mode) else if (mode == LazyThreadSafetyMode.PublicationOnly) return LazyHelpers.PUBLICATION_ONLY_SENTINEL; else if (mode != LazyThreadSafetyMode.None) - throw new ArgumentOutOfRangeException("mode", Environment.GetResourceString("Lazy_ctor_ModeInvalid")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.mode, ExceptionResource.Lazy_ctor_ModeInvalid); return null; // None mode } @@ -432,7 +432,7 @@ private Boxed CreateValue() { // check for recursion if (mode != LazyThreadSafetyMode.PublicationOnly && m_valueFactory == ALREADY_INVOKED_SENTINEL) - throw new InvalidOperationException(Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Lazy_Value_RecursiveCallsToValue); Func factory = m_valueFactory; if (mode != LazyThreadSafetyMode.PublicationOnly) // only detect recursion on None and ExecutionAndPublication modes diff --git a/src/mscorlib/src/System/Progress.cs b/src/mscorlib/src/System/Progress.cs index 8800c0322a12..d7367456c46f 100644 --- a/src/mscorlib/src/System/Progress.cs +++ b/src/mscorlib/src/System/Progress.cs @@ -63,7 +63,7 @@ public Progress() /// The is null (Nothing in Visual Basic). public Progress(Action handler) : this() { - if (handler == null) throw new ArgumentNullException("handler"); + if (handler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.handler); m_handler = handler; } diff --git a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs index 5e7f83f2dfb9..fbc73e18ea19 100644 --- a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -701,7 +701,7 @@ private ModuleBuilder DefineDynamicModuleInternalNoLock( if (symWriter == null) { // cannot find SymWriter - throw TypeLoadException since we couldnt find the type. - throw new TypeLoadException(Environment.GetResourceString(ResId.MissingType, "SymWriter")); + ThrowHelper.ThrowTypeLoadException(ExceptionResource.MissingType, ExceptionArgument.SymWriter); } new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); @@ -1749,8 +1749,8 @@ private void SaveNoLock(String assemblyFileName, if (m_assemblyData.m_isSaved == true) { // assembly has been saved before! - throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_AssemblyHasBeenSaved, - InternalAssembly.GetSimpleName())); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_AssemblyHasBeenSaved, + InternalAssembly.GetSimpleName()); } if ((m_assemblyData.m_access & AssemblyBuilderAccess.Save) != AssemblyBuilderAccess.Save) @@ -2035,7 +2035,7 @@ private void SaveNoLock(String assemblyFileName, } } #endif // FEATURE_CORECLR - + #if FEATURE_CAS_POLICY [System.Security.SecurityCritical] // auto-generated private void AddDeclarativeSecurity(PermissionSet pset, SecurityAction action) @@ -2045,7 +2045,7 @@ private void AddDeclarativeSecurity(PermissionSet pset, SecurityAction action) AddDeclarativeSecurity(GetNativeHandle(), action, blob, blob.Length); } #endif // FEATURE_CAS_POLICY - + internal bool IsPersistable() { #if !FEATURE_CORECLR // AssemblyBuilderAccess.Save is never set in CoreCLR diff --git a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs index 15dece9fcb8b..23ac6309d771 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs @@ -297,7 +297,7 @@ internal __ExceptionInfo[] GetExceptions() __ExceptionInfo []temp; if (m_currExcStackCount != 0) { - throw new NotSupportedException(Environment.GetResourceString(ResId.Argument_UnclosedExceptionBlock)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.Argument_UnclosedExceptionBlock); } if (m_exceptionCount == 0) diff --git a/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs b/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs index c1b4ee5fe182..af040da6fac5 100644 --- a/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs +++ b/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs @@ -89,7 +89,7 @@ internal MemberInfoSerializationHolder(SerializationInfo info, StreamingContext [System.Security.SecurityCritical] // auto-generated public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { - throw new NotSupportedException(Environment.GetResourceString(ResId.NotSupported_Method)); + ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_Method); } #endregion @@ -98,7 +98,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte public virtual Object GetRealObject(StreamingContext context) { if (m_memberName == null || m_reflectedType == null || m_memberType == 0) - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_InsufficientState)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_InsufficientState); BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | @@ -158,7 +158,8 @@ public virtual Object GetRealObject(StreamingContext context) } } - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_UnknownMember, m_memberName)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_UnknownMember, m_memberName); + return default(PropertyInfo); } #endregion @@ -166,7 +167,7 @@ public virtual Object GetRealObject(StreamingContext context) case MemberTypes.Constructor: { if (m_signature == null) - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_NullSignature)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullSignature); ConstructorInfo[] constructors = m_reflectedType.GetMember(m_memberName, MemberTypes.Constructor, bindingFlags) as ConstructorInfo[]; @@ -190,7 +191,8 @@ public virtual Object GetRealObject(StreamingContext context) } } - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_UnknownMember, m_memberName)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_UnknownMember, m_memberName); + return default(ConstructorInfo); } #endregion @@ -200,7 +202,7 @@ public virtual Object GetRealObject(StreamingContext context) MethodInfo methodInfo = null; if (m_signature == null) - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_NullSignature)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NullSignature); Type[] genericArguments = m_info.GetValueNoThrow("GenericArguments", typeof(Type[])) as Type[]; @@ -261,7 +263,7 @@ public virtual Object GetRealObject(StreamingContext context) } if (methodInfo == null) - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_UnknownMember, m_memberName)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_UnknownMember, m_memberName); if (!methodInfo.IsGenericMethodDefinition) return methodInfo; diff --git a/src/mscorlib/src/System/Reflection/ParameterInfo.cs b/src/mscorlib/src/System/Reflection/ParameterInfo.cs index 63c6330b0a48..2464e89e49cb 100644 --- a/src/mscorlib/src/System/Reflection/ParameterInfo.cs +++ b/src/mscorlib/src/System/Reflection/ParameterInfo.cs @@ -217,7 +217,7 @@ public object GetRealObject(StreamingContext context) // instance based on just two of them (MemberImpl and PositionImpl). if (MemberImpl == null) - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_InsufficientState)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_InsufficientState); ParameterInfo[] args = null; @@ -227,31 +227,29 @@ public object GetRealObject(StreamingContext context) case MemberTypes.Method: if (PositionImpl == -1) { - if (MemberImpl.MemberType == MemberTypes.Method) - return ((MethodInfo)MemberImpl).ReturnParameter; - else - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo)); + if (MemberImpl.MemberType != MemberTypes.Method) + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_BadParameterInfo); + return ((MethodInfo)MemberImpl).ReturnParameter; } else { args = ((MethodBase)MemberImpl).GetParametersNoCopy(); - if (args != null && PositionImpl < args.Length) - return args[PositionImpl]; - else - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo)); + if (args == null || PositionImpl >= args.Length) + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_BadParameterInfo); + return args[PositionImpl]; } case MemberTypes.Property: args = ((RuntimePropertyInfo)MemberImpl).GetIndexParametersNoCopy(); - if (args != null && PositionImpl > -1 && PositionImpl < args.Length) - return args[PositionImpl]; - else - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo)); + if (args == null || PositionImpl < 0 || PositionImpl >= args.Length) + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_BadParameterInfo); + return args[PositionImpl]; default: - throw new SerializationException(Environment.GetResourceString(ResId.Serialization_NoParameterInfo)); + ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_NoParameterInfo); + return default(ParameterInfo); } } #endregion diff --git a/src/mscorlib/src/System/ResId.cs b/src/mscorlib/src/System/ResId.cs deleted file mode 100644 index e6a2423c28bf..000000000000 --- a/src/mscorlib/src/System/ResId.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** Purpose: Contains identifiers for each of the resources -** specified in resources.txt -** -** -===========================================================*/ -namespace System { - //This class contains only static members and does not need to be serializable. - using System.Configuration.Assemblies; - using System; - internal static class ResId { - // Only statics, does not need to be marked with the serializable attribute - internal const String Arg_ArrayLengthsDiffer="Arg_ArrayLengthsDiffer"; - internal const String Argument_InvalidNumberOfMembers="Argument_InvalidNumberOfMembers"; - internal const String Argument_UnequalMembers="Argument_UnequalMembers"; - internal const String Argument_SpecifyValueSize="Argument_SpecifyValueSize"; - internal const String Argument_UnmatchingSymScope="Argument_UnmatchingSymScope"; - internal const String Argument_NotInExceptionBlock="Argument_NotInExceptionBlock"; - internal const String Argument_NotExceptionType="Argument_NotExceptionType"; - internal const String Argument_InvalidLabel="Argument_InvalidLabel"; - internal const String Argument_UnclosedExceptionBlock="Argument_UnclosedExceptionBlock"; - internal const String Argument_MissingDefaultConstructor="Argument_MissingDefaultConstructor"; - internal const String Argument_TooManyFinallyClause="Argument_TooManyFinallyClause"; - internal const String Argument_NotInTheSameModuleBuilder="Argument_NotInTheSameModuleBuilder"; - internal const String Argument_BadCurrentLocalVariable="Argument_BadCurrentLocalVariable"; - internal const String Argument_DuplicateModuleName="Argument_DuplicateModuleName"; - internal const String Argument_BadPersistableModuleInTransientAssembly="Argument_BadPersistableModuleInTransientAssembly"; - internal const String Argument_HasToBeArrayClass="Argument_HasToBeArrayClass"; - internal const String Argument_InvalidDirectory="Argument_InvalidDirectory"; - - internal const String MissingType="MissingType"; - internal const String MissingModule="MissingModule"; - - internal const String ArgumentOutOfRange_Index="ArgumentOutOfRange_Index"; - internal const String ArgumentOutOfRange_Range="ArgumentOutOfRange_Range"; - - internal const String ExecutionEngine_YoureHosed="ExecutionEngine_YoureHosed"; - - internal const String Format_NeedSingleChar="Format_NeedSingleChar"; - internal const String Format_StringZeroLength="Format_StringZeroLength"; - - internal const String InvalidOperation_EnumEnded="InvalidOperation_EnumEnded"; - internal const String InvalidOperation_EnumFailedVersion="InvalidOperation_EnumFailedVersion"; - internal const String InvalidOperation_EnumNotStarted="InvalidOperation_EnumNotStarted"; - internal const String InvalidOperation_EnumOpCantHappen="InvalidOperation_EnumOpCantHappen"; - internal const String InvalidOperation_InternalState="InvalidOperation_InternalState"; - internal const String InvalidOperation_ModifyRONumFmtInfo="InvalidOperation_ModifyRONumFmtInfo"; - internal const String InvalidOperation_MethodBaked="InvalidOperation_MethodBaked"; - internal const String InvalidOperation_NotADebugModule="InvalidOperation_NotADebugModule"; - internal const String InvalidOperation_MethodHasBody="InvalidOperation_MethodHasBody"; - internal const String InvalidOperation_OpenLocalVariableScope="InvalidOperation_OpenLocalVariableScope"; - internal const String InvalidOperation_TypeHasBeenCreated="InvalidOperation_TypeHasBeenCreated"; - internal const String InvalidOperation_RefedAssemblyNotSaved="InvalidOperation_RefedAssemblyNotSaved"; - internal const String InvalidOperation_AssemblyHasBeenSaved="InvalidOperation_AssemblyHasBeenSaved"; - internal const String InvalidOperation_ModuleHasBeenSaved="InvalidOperation_ModuleHasBeenSaved"; - internal const String InvalidOperation_CannotAlterAssembly="InvalidOperation_CannotAlterAssembly"; - - internal const String NotSupported_CannotSaveModuleIndividually="NotSupported_CannotSaveModuleIndividually"; - internal const String NotSupported_Constructor="NotSupported_Constructor"; - internal const String NotSupported_Method="NotSupported_Method"; - internal const String NotSupported_NYI="NotSupported_NYI"; - internal const String NotSupported_DynamicModule="NotSupported_DynamicModule"; - internal const String NotSupported_NotDynamicModule="NotSupported_NotDynamicModule"; - internal const String NotSupported_NotAllTypesAreBaked="NotSupported_NotAllTypesAreBaked"; - internal const String NotSupported_SortedListNestedWrite="NotSupported_SortedListNestedWrite"; - - - internal const String Serialization_ArrayInvalidLength="Serialization_ArrayInvalidLength"; - internal const String Serialization_ArrayNoLength="Serialization_ArrayNoLength"; - internal const String Serialization_CannotGetType="Serialization_CannotGetType"; - internal const String Serialization_InsufficientState="Serialization_InsufficientState"; - internal const String Serialization_InvalidID="Serialization_InvalidID"; - internal const String Serialization_MalformedArray="Serialization_MalformedArray"; - internal const String Serialization_MultipleMembers="Serialization_MultipleMembers"; - internal const String Serialization_NoID="Serialization_NoID"; - internal const String Serialization_NoType="Serialization_NoType"; - internal const String Serialization_NoBaseType="Serialization_NoBaseType"; - internal const String Serialization_NullSignature="Serialization_NullSignature"; - internal const String Serialization_UnknownMember="Serialization_UnknownMember"; - internal const String Serialization_BadParameterInfo="Serialization_BadParameterInfo"; - internal const String Serialization_NoParameterInfo="Serialization_NoParameterInfo"; - - internal const String WeakReference_NoLongerValid="WeakReference_NoLongerValid"; - internal const String Loader_InvalidPath="Loader_InvalidPath"; - } -} diff --git a/src/mscorlib/src/System/Resources/ResourceReader.cs b/src/mscorlib/src/System/Resources/ResourceReader.cs index a269d5c5fe85..3360354c5868 100644 --- a/src/mscorlib/src/System/Resources/ResourceReader.cs +++ b/src/mscorlib/src/System/Resources/ResourceReader.cs @@ -1345,8 +1345,8 @@ public bool MoveNext() public Object Key { [System.Security.SecuritySafeCritical] // auto-generated get { - if (_currentName == ENUM_DONE) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); - if (!_currentIsValid) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + if (_currentName == ENUM_DONE) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (!_currentIsValid) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); if (_reader._resCache == null) throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed")); return _reader.AllocateStringForNameIndex(_currentName, out _dataPosition); @@ -1369,8 +1369,8 @@ internal int DataPosition { public DictionaryEntry Entry { [System.Security.SecuritySafeCritical] // auto-generated get { - if (_currentName == ENUM_DONE) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); - if (!_currentIsValid) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + if (_currentName == ENUM_DONE) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (!_currentIsValid) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); if (_reader._resCache == null) throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed")); String key; @@ -1401,8 +1401,8 @@ public DictionaryEntry Entry { public Object Value { get { - if (_currentName == ENUM_DONE) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); - if (!_currentIsValid) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); + if (_currentName == ENUM_DONE) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); + if (!_currentIsValid) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); if (_reader._resCache == null) throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed")); // Consider using _resCache here, eventually, if diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs index af1381c366ef..f86d94e85aba 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs @@ -259,8 +259,8 @@ public bool MoveNext() public IKeyValuePair Current { get { - if (_current < _start) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); - if (_current > _end) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); + if (_current < _start) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumNotStarted); + if (_current > _end) ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumEnded); return new CLRIKeyValuePairImpl(ref _array[_current]); } } diff --git a/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs b/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs index 3f9937c3f23e..b1f634c707a3 100644 --- a/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs +++ b/src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs @@ -688,15 +688,15 @@ internal static Task FromAsyncImpl( ref StackCrawlMark stackMark) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult); if (endFunction == null && endAction == null) - throw new ArgumentNullException("endMethod"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.endMethod); Contract.Requires((endFunction != null) != (endAction != null), "Both endFunction and endAction were non-null"); if (scheduler == null) - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); Contract.EndContractBlock(); TaskFactory.CheckFromAsyncOptions(creationOptions, false); @@ -811,10 +811,10 @@ internal static Task FromAsyncImpl(Func FromAsyncImpl(Func FromAsyncImpl(Func FromAsyncImpl(Func; - if (promise == null) throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndCalledMultiple"), "asyncResult"); + if (promise == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult); // Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily var thisRef = promise.m_thisRef; var endMethod = promise.m_endMethod; promise.m_thisRef = default(TInstance); promise.m_endMethod = null; - if (endMethod == null) throw new ArgumentException(Environment.GetResourceString("InvalidOperation_WrongAsyncResultOrEndCalledMultiple"), "asyncResult"); + if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult); // Complete the promise. If the IAsyncResult completed synchronously, // we'll instead complete the promise at the call site. @@ -1491,7 +1491,7 @@ private static Task CreateCanceledTask(TaskContinuationOptions continua [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1522,7 +1522,7 @@ public Task ContinueWhenAll(Task[] tasks, Func continu [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1559,7 +1559,7 @@ public Task ContinueWhenAll(Task[] tasks, Func continu [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1607,7 +1607,7 @@ public Task ContinueWhenAll(Task[] tasks, Func continu public Task ContinueWhenAll(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1634,7 +1634,7 @@ public Task ContinueWhenAll(Task[] tasks, Func continu [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1667,7 +1667,7 @@ public Task ContinueWhenAll(Task[ public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1706,7 +1706,7 @@ public Task ContinueWhenAll(Task[ public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1755,7 +1755,7 @@ public Task ContinueWhenAll(Task[ public Task ContinueWhenAll(Task[] tasks, Func[], TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1771,10 +1771,10 @@ internal static Task ContinueWhenAllImpl(Task ContinueWhenAllImpl(Task[] tasks, { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); //ArgumentNullException of continuationFunction or continuationAction is checked by the caller Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null"); - if (scheduler == null) throw new ArgumentNullException("scheduler"); + if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); Contract.EndContractBlock(); // Check tasks array and make defensive copy @@ -1891,7 +1891,7 @@ internal static Task ContinueWhenAllImpl(Task[] tasks, [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1922,7 +1922,7 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1959,7 +1959,7 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2007,7 +2007,7 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat public Task ContinueWhenAny(Task[] tasks, Func continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2034,7 +2034,7 @@ public Task ContinueWhenAny(Task[] tasks, Func continuat [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2067,7 +2067,7 @@ public Task ContinueWhenAny(Task[ public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2106,7 +2106,7 @@ public Task ContinueWhenAny(Task[ public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2155,7 +2155,7 @@ public Task ContinueWhenAny(Task[ public Task ContinueWhenAny(Task[] tasks, Func, TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2170,12 +2170,12 @@ internal static Task ContinueWhenAnyImpl(Task[] tasks, { // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); - if (tasks == null) throw new ArgumentNullException("tasks"); - if(tasks.Length == 0) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); + if(tasks.Length == 0) ThrowHelper.ThrowArgumentException( ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); //ArgumentNullException of continuationFunction or continuationAction is checked by the caller Contract.Requires((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null"); - if (scheduler == null) throw new ArgumentNullException("scheduler"); + if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); Contract.EndContractBlock(); // Call common ContinueWhenAny() setup logic, extract starter @@ -2218,11 +2218,11 @@ internal static Task ContinueWhenAnyImpl(Task Int32.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout); } return Wait((int)totalMilliseconds, default(CancellationToken)); @@ -3124,7 +3124,7 @@ public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) { if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout); } Contract.EndContractBlock(); @@ -3879,13 +3879,13 @@ private Task ContinueWith(Action continuationAction, TaskScheduler schedul // Throw on continuation with null action if (continuationAction == null) { - throw new ArgumentNullException("continuationAction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction); } // Throw on continuation with null TaskScheduler if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } Contract.EndContractBlock(); @@ -4081,13 +4081,13 @@ private Task ContinueWith(Action continuationAction, Object state, // Throw on continuation with null action if (continuationAction == null) { - throw new ArgumentNullException("continuationAction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction); } // Throw on continuation with null TaskScheduler if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } Contract.EndContractBlock(); @@ -4296,13 +4296,13 @@ private Task ContinueWith(Func continuationFunc // Throw on continuation with null function if (continuationFunction == null) { - throw new ArgumentNullException("continuationFunction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); } // Throw on continuation with null task scheduler if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } Contract.EndContractBlock(); @@ -4515,13 +4515,13 @@ private Task ContinueWith(Func continua // Throw on continuation with null function if (continuationFunction == null) { - throw new ArgumentNullException("continuationFunction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); } // Throw on continuation with null task scheduler if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } Contract.EndContractBlock(); @@ -4573,7 +4573,7 @@ internal static void CreationOptionsFromContinuationOptions( TaskContinuationOptions illegalMask = TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.LongRunning; if ((continuationOptions & illegalMask) == illegalMask) { - throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_ContinueWith_ESandLR")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_ESandLR); } // Check that no illegal options were specified @@ -4581,13 +4581,13 @@ internal static void CreationOptionsFromContinuationOptions( ~(creationOptionsMask | NotOnAnything | TaskContinuationOptions.LazyCancellation | TaskContinuationOptions.ExecuteSynchronously)) != 0) { - throw new ArgumentOutOfRangeException("continuationOptions"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions); } // Check that we didn't specify "not on anything" if ((continuationOptions & NotOnAnything) == NotOnAnything) { - throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_ContinueWith_NotOnAnything")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_NotOnAnything); } // This passes over all but LazyCancellation, which has no representation in TaskCreationOptions @@ -4912,7 +4912,7 @@ public static bool WaitAll(Task[] tasks, TimeSpan timeout) long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout); } return WaitAll(tasks, (int)totalMilliseconds); @@ -5022,11 +5022,11 @@ public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationTo { if (tasks == null) { - throw new ArgumentNullException("tasks"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); } if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout); } Contract.EndContractBlock(); @@ -5054,7 +5054,7 @@ public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationTo if (task == null) { - throw new ArgumentException(Environment.GetResourceString("Task_WaitMulti_NullTask"), "tasks"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks); } bool taskIsCompleted = task.IsCompleted; @@ -5135,7 +5135,7 @@ public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationTo // Now gather up and throw all of the exceptions. foreach (var task in tasks) AddExceptionsForCompletedTask(ref exceptions, task); Contract.Assert(exceptions != null, "Should have seen at least one exception"); - throw new AggregateException(exceptions); + ThrowHelper.ThrowAggregateException(exceptions); } return returnValue; @@ -5258,7 +5258,7 @@ internal static void FastWaitAll(Task[] tasks) // If one or more threw exceptions, aggregate them. if (exceptions != null) { - throw new AggregateException(exceptions); + ThrowHelper.ThrowAggregateException(exceptions); } } @@ -5339,7 +5339,7 @@ public static int WaitAny(Task[] tasks, TimeSpan timeout) long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.timeout); } return WaitAny(tasks, (int)totalMilliseconds); @@ -5437,11 +5437,11 @@ public static int WaitAny(Task[] tasks, int millisecondsTimeout, CancellationTok { if (tasks == null) { - throw new ArgumentNullException("tasks"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); } if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsTimeout); } Contract.EndContractBlock(); @@ -5458,7 +5458,7 @@ public static int WaitAny(Task[] tasks, int millisecondsTimeout, CancellationTok if (task == null) { - throw new ArgumentException(Environment.GetResourceString("Task_WaitMulti_NullTask"), "tasks"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks); } if (signaledTaskIndex == -1 && task.IsCompleted) @@ -5516,7 +5516,7 @@ public static Task FromException(Exception exception) /// The faulted task. public static Task FromException(Exception exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); Contract.EndContractBlock(); var task = new Task(); @@ -5531,7 +5531,7 @@ public static Task FromException(Exception exception) public static Task FromCanceled(CancellationToken cancellationToken) { if (!cancellationToken.IsCancellationRequested) - throw new ArgumentOutOfRangeException("cancellationToken"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken); Contract.EndContractBlock(); return new Task(true, TaskCreationOptions.None, cancellationToken); } @@ -5543,7 +5543,7 @@ public static Task FromCanceled(CancellationToken cancellationToken) public static Task FromCanceled(CancellationToken cancellationToken) { if (!cancellationToken.IsCancellationRequested) - throw new ArgumentOutOfRangeException("cancellationToken"); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken); Contract.EndContractBlock(); return new Task(true, default(TResult), TaskCreationOptions.None, cancellationToken); } @@ -5554,7 +5554,7 @@ public static Task FromCanceled(CancellationToken cancellation /// The canceled task. internal static Task FromCancellation(OperationCanceledException exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); Contract.EndContractBlock(); var task = new Task(); @@ -5690,7 +5690,7 @@ public static Task Run(Func function) public static Task Run(Func function, CancellationToken cancellationToken) { // Check arguments - if (function == null) throw new ArgumentNullException("function"); + if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function); Contract.EndContractBlock(); if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource) @@ -5741,7 +5741,7 @@ public static Task Run(Func> function) public static Task Run(Func> function, CancellationToken cancellationToken) { // Check arguments - if (function == null) throw new ArgumentNullException("function"); + if (function == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function); Contract.EndContractBlock(); if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource) @@ -5806,7 +5806,7 @@ public static Task Delay(TimeSpan delay, CancellationToken cancellationToken) long totalMilliseconds = (long)delay.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("delay", Environment.GetResourceString("Task_Delay_InvalidDelay")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.delay, ExceptionResource.Task_Delay_InvalidDelay); } return Delay((int)totalMilliseconds, cancellationToken); @@ -5850,7 +5850,7 @@ public static Task Delay(int millisecondsDelay, CancellationToken cancellationTo // Throw on non-sensical time if (millisecondsDelay < -1) { - throw new ArgumentOutOfRangeException("millisecondsDelay", Environment.GetResourceString("Task_Delay_InvalidMillisecondsDelay")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsDelay, ExceptionResource.Task_Delay_InvalidMillisecondsDelay); } Contract.EndContractBlock(); @@ -5982,18 +5982,18 @@ public static Task WhenAll(IEnumerable tasks) taskArray = new Task[taskCollection.Count]; foreach (var task in tasks) { - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); taskArray[index++] = task; } return InternalWhenAll(taskArray); } // Do some argument checking and convert tasks to a List (and later an array). - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); List taskList = new List(); foreach (Task task in tasks) { - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); taskList.Add(task); } @@ -6031,7 +6031,7 @@ public static Task WhenAll(IEnumerable tasks) public static Task WhenAll(params Task[] tasks) { // Do some argument checking and make a defensive copy of the tasks array - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); Contract.EndContractBlock(); int taskCount = tasks.Length; @@ -6041,7 +6041,7 @@ public static Task WhenAll(params Task[] tasks) for (int i = 0; i < taskCount; i++) { Task task = tasks[i]; - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); tasksCopy[i] = task; } @@ -6233,18 +6233,18 @@ public static Task WhenAll(IEnumerable> tasks) taskArray = new Task[taskCollection.Count]; foreach (var task in tasks) { - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); taskArray[index++] = task; } return InternalWhenAll(taskArray); } // Do some argument checking and convert tasks into a List (later an array) - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); List> taskList = new List>(); foreach (Task task in tasks) { - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); taskList.Add(task); } @@ -6285,7 +6285,7 @@ public static Task WhenAll(IEnumerable> tasks) public static Task WhenAll(params Task[] tasks) { // Do some argument checking and make a defensive copy of the tasks array - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); Contract.EndContractBlock(); int taskCount = tasks.Length; @@ -6295,7 +6295,7 @@ public static Task WhenAll(params Task[] tasks) for (int i = 0; i < taskCount; i++) { Task task = tasks[i]; - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); tasksCopy[i] = task; } @@ -6457,10 +6457,10 @@ internal override bool ShouldNotifyDebuggerOfWaitCompletion /// public static Task WhenAny(params Task[] tasks) { - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); if (tasks.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); } Contract.EndContractBlock(); @@ -6471,7 +6471,7 @@ public static Task WhenAny(params Task[] tasks) for (int i = 0; i < taskCount; i++) { Task task = tasks[i]; - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); tasksCopy[i] = task; } @@ -6496,7 +6496,7 @@ public static Task WhenAny(params Task[] tasks) /// public static Task WhenAny(IEnumerable tasks) { - if (tasks == null) throw new ArgumentNullException("tasks"); + if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); Contract.EndContractBlock(); // Make a defensive copy, as the user may manipulate the tasks collection @@ -6504,13 +6504,13 @@ public static Task WhenAny(IEnumerable tasks) List taskList = new List(); foreach (Task task in tasks) { - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); taskList.Add(task); } if (taskList.Count == 0) { - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks"); + ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); } // Previously implemented CommonCWAnyLogic() can handle the rest diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs b/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs index 6ff70eb79c27..8b1dd2a62f75 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs @@ -156,7 +156,7 @@ private void SpinUntilCompleted() /// The was disposed. public bool TrySetException(Exception exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); bool rval = m_task.TrySetException(exception); if (!rval && !m_task.IsCompleted) SpinUntilCompleted(); @@ -185,18 +185,18 @@ public bool TrySetException(Exception exception) /// The was disposed. public bool TrySetException(IEnumerable exceptions) { - if (exceptions == null) throw new ArgumentNullException("exceptions"); + if (exceptions == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exceptions); List defensiveCopy = new List(); foreach (Exception e in exceptions) { if (e == null) - throw new ArgumentException(Environment.GetResourceString("TaskCompletionSourceT_TrySetException_NullException"), "exceptions"); + ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NullException, ExceptionArgument.exceptions); defensiveCopy.Add(e); } if (defensiveCopy.Count == 0) - throw new ArgumentException(Environment.GetResourceString("TaskCompletionSourceT_TrySetException_NoExceptions"), "exceptions"); + ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions, ExceptionArgument.exceptions); bool rval = m_task.TrySetException(defensiveCopy); if (!rval && !m_task.IsCompleted) SpinUntilCompleted(); @@ -238,11 +238,11 @@ internal bool TrySetException(IEnumerable exceptions) /// The was disposed. public void SetException(Exception exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); if (!TrySetException(exception)) { - throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } } @@ -268,7 +268,7 @@ public void SetException(IEnumerable exceptions) { if (!TrySetException(exceptions)) { - throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } } @@ -316,7 +316,7 @@ public bool TrySetResult(TResult result) public void SetResult(TResult result) { if (!TrySetResult(result)) - throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } /// @@ -364,7 +364,7 @@ public bool TrySetCanceled(CancellationToken cancellationToken) public void SetCanceled() { if(!TrySetCanceled()) - throw new InvalidOperationException(Environment.GetResourceString("TaskT_TransitionToFinal_AlreadyCompleted")); + ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } } } diff --git a/src/mscorlib/src/System/Threading/Tasks/future.cs b/src/mscorlib/src/System/Threading/Tasks/future.cs index 9ce7ab60ebb1..f71f5d172066 100644 --- a/src/mscorlib/src/System/Threading/Tasks/future.cs +++ b/src/mscorlib/src/System/Threading/Tasks/future.cs @@ -350,7 +350,7 @@ internal Task(Func valueSelector, Task parent, CancellationToken cancel { if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0) { - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating); } } @@ -380,7 +380,7 @@ internal Task(Delegate valueSelector, object state, Task parent, CancellationTok { if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0) { - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating); } } @@ -391,15 +391,15 @@ internal static Task StartNew(Task parent, Func function, Canc { if (function == null) { - throw new ArgumentNullException("function"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0) { - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating); } // Create and schedule the future. @@ -415,15 +415,15 @@ internal static Task StartNew(Task parent, Func functi { if (function == null) { - throw new ArgumentNullException("function"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.function); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0) { - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("TaskT_ctor_SelfReplicating")); + ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.creationOptions, ExceptionResource.TaskT_ctor_SelfReplicating); } // Create and schedule the future. @@ -879,12 +879,12 @@ internal Task ContinueWith(Action> continuationAction, TaskSchedul { if (continuationAction == null) { - throw new ArgumentNullException("continuationAction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } TaskCreationOptions creationOptions; @@ -1083,12 +1083,12 @@ internal Task ContinueWith(Action, Object> continuationAction, Obj { if (continuationAction == null) { - throw new ArgumentNullException("continuationAction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationAction); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } TaskCreationOptions creationOptions; @@ -1310,12 +1310,12 @@ internal Task ContinueWith(Func, TNewResul { if (continuationFunction == null) { - throw new ArgumentNullException("continuationFunction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } TaskCreationOptions creationOptions; @@ -1544,12 +1544,12 @@ internal Task ContinueWith(Func, Object, T { if (continuationFunction == null) { - throw new ArgumentNullException("continuationFunction"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.continuationFunction); } if (scheduler == null) { - throw new ArgumentNullException("scheduler"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } TaskCreationOptions creationOptions; @@ -1575,7 +1575,7 @@ ref stackMark #endregion #endregion - + /// /// Subscribes an to receive notification of the final state of this . /// @@ -1594,7 +1594,7 @@ ref stackMark IDisposable IObservable.Subscribe(IObserver observer) { if (observer == null) - throw new System.ArgumentNullException("observer"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.observer); var continuationTask = diff --git a/src/mscorlib/src/System/ThrowHelper.cs b/src/mscorlib/src/System/ThrowHelper.cs index e1cdd30081af..1c05690b1f69 100644 --- a/src/mscorlib/src/System/ThrowHelper.cs +++ b/src/mscorlib/src/System/ThrowHelper.cs @@ -36,27 +36,39 @@ namespace System { // multiple times for different instantiation. // - using System.Runtime.CompilerServices; + using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Diagnostics.Contracts; + using Collections.Generic; [Pure] - internal static class ThrowHelper { - internal static void ThrowArgumentOutOfRangeException() { - ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); + internal static class ThrowHelper + { + internal static void ThrowIndexArgumentOutOfRange_IndexException() + { + throw new ArgumentOutOfRangeException( + GetArgumentName(ExceptionArgument.index), + Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_Index))); + } + + internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException() + { + throw new ArgumentOutOfRangeException( + GetArgumentName(ExceptionArgument.index), + Environment.GetResourceString(GetResourceName(ExceptionResource.ArgumentOutOfRange_NeedNonNegNum))); } internal static void ThrowWrongKeyTypeArgumentException(object key, Type targetType) { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), "key"); + throw new ArgumentException(Environment.GetResourceString(GetResourceName(ExceptionResource.Arg_WrongType), key, targetType), GetArgumentName(ExceptionArgument.key)); } internal static void ThrowWrongValueTypeArgumentException(object value, Type targetType) { - throw new ArgumentException(Environment.GetResourceString("Arg_WrongType", value, targetType), "value"); + throw new ArgumentException(Environment.GetResourceString(GetResourceName(ExceptionResource.Arg_WrongType), value, targetType), GetArgumentName(ExceptionArgument.value)); } #if FEATURE_CORECLR internal static void ThrowAddingDuplicateWithKeyArgumentException(object key) { - throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicateWithKey", key)); + throw new ArgumentException(Environment.GetResourceString(GetResourceName(ExceptionResource.Argument_AddingDuplicateWithKey), key)); } #endif @@ -76,6 +88,16 @@ internal static void ThrowArgumentNullException(ExceptionArgument argument) { throw new ArgumentNullException(GetArgumentName(argument)); } + internal static void ThrowArgumentNullException(ExceptionResource resource) + { + throw new ArgumentNullException(Environment.GetResourceString(GetResourceName(resource))); + } + + internal static void ThrowFormatException(ExceptionResource resource) + { + throw new FormatException(Environment.GetResourceString(GetResourceName(resource))); + } + internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) { throw new ArgumentOutOfRangeException(GetArgumentName(argument)); } @@ -85,18 +107,55 @@ internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument Environment.GetResourceString(GetResourceName(resource))); } - internal static void ThrowInvalidOperationException(ExceptionResource resource) { + internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument, int paramNumber, ExceptionResource resource) + { + throw new ArgumentOutOfRangeException(GetArgumentName(argument) + "[" + paramNumber.ToString()+ "]", + Environment.GetResourceString(GetResourceName(resource))); + } + + internal static void ThrowInvalidOperationException() + { + throw new InvalidOperationException(); + } + + internal static void ThrowInvalidOperationException(ExceptionResource resource) + { throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource))); } + internal static void ThrowInvalidOperationException(ExceptionResource resource, string value) + { + throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource), value)); + } + + internal static void ThrowInvalidOperationException(ExceptionResource resource, Exception e) + { + throw new InvalidOperationException(Environment.GetResourceString(GetResourceName(resource)), e); + } + internal static void ThrowSerializationException(ExceptionResource resource) { throw new SerializationException(Environment.GetResourceString(GetResourceName(resource))); } + internal static void ThrowSerializationException(ExceptionResource resource, string memberName) + { + throw new SerializationException(Environment.GetResourceString(GetResourceName(resource), memberName)); + } + + internal static void ThrowRankException(ExceptionResource resource) + { + throw new RankException(Environment.GetResourceString(GetResourceName(resource))); + } + internal static void ThrowSecurityException(ExceptionResource resource) { throw new System.Security.SecurityException(Environment.GetResourceString(GetResourceName(resource))); } + internal static void ThrowNotSupportedException() + { + throw new NotSupportedException(); + } + internal static void ThrowNotSupportedException(ExceptionResource resource) { throw new NotSupportedException(Environment.GetResourceString(GetResourceName(resource))); } @@ -109,333 +168,57 @@ internal static void ThrowObjectDisposedException(string objectName, ExceptionRe throw new ObjectDisposedException(objectName, Environment.GetResourceString(GetResourceName(resource))); } - // Allow nulls for reference types and Nullable, but not for value types. - internal static void IfNullAndNullsAreIllegalThenThrow(object value, ExceptionArgument argName) { - // Note that default(T) is not equal to null for value types except when T is Nullable. - if (value == null && !(default(T) == null)) - ThrowHelper.ThrowArgumentNullException(argName); + internal static void ThrowObjectDisposedException(ExceptionResource resource) + { + throw new ObjectDisposedException(null, Environment.GetResourceString(GetResourceName(resource))); } - // - // This function will convert an ExceptionArgument enum value to the argument name string. - // - internal static string GetArgumentName(ExceptionArgument argument) { - string argumentName = null; - - switch (argument) { - case ExceptionArgument.action: - argumentName = "action"; - break; - - case ExceptionArgument.array: - argumentName = "array"; - break; - - case ExceptionArgument.arrayIndex: - argumentName = "arrayIndex"; - break; - - case ExceptionArgument.capacity: - argumentName = "capacity"; - break; - - case ExceptionArgument.collection: - argumentName = "collection"; - break; - - case ExceptionArgument.comparison: - argumentName = "comparison"; - break; - - case ExceptionArgument.list: - argumentName = "list"; - break; - - case ExceptionArgument.converter: - argumentName = "converter"; - break; - - case ExceptionArgument.count: - argumentName = "count"; - break; - - case ExceptionArgument.dictionary: - argumentName = "dictionary"; - break; - - case ExceptionArgument.dictionaryCreationThreshold: - argumentName = "dictionaryCreationThreshold"; - break; - - case ExceptionArgument.index: - argumentName = "index"; - break; - - case ExceptionArgument.info: - argumentName = "info"; - break; - - case ExceptionArgument.key: - argumentName = "key"; - break; - - case ExceptionArgument.match: - argumentName = "match"; - break; - - case ExceptionArgument.obj: - argumentName = "obj"; - break; - - case ExceptionArgument.queue: - argumentName = "queue"; - break; - - case ExceptionArgument.stack: - argumentName = "stack"; - break; - - case ExceptionArgument.startIndex: - argumentName = "startIndex"; - break; - - case ExceptionArgument.value: - argumentName = "value"; - break; - - case ExceptionArgument.name: - argumentName = "name"; - break; + internal static void ThrowTypeLoadException(ExceptionResource resource, ExceptionArgument argument) + { + throw new TypeLoadException(Environment.GetResourceString(GetResourceName(resource), GetArgumentName(argument))); + } - case ExceptionArgument.mode: - argumentName = "mode"; - break; + internal static void ThrowNotImplementedException() + { + throw new NotImplementedException(); + } - case ExceptionArgument.item: - argumentName = "item"; - break; + internal static void ThrowAggregateException(IEnumerable innerExceptions) + { + throw new AggregateException(innerExceptions); + } - case ExceptionArgument.options: - argumentName = "options"; - break; - case ExceptionArgument.view: - argumentName = "view"; - break; - case ExceptionArgument.sourceBytesToCopy: - argumentName = "sourceBytesToCopy"; - break; + // Allow nulls for reference types and Nullable, but not for value types. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void IfNullAndNullsAreIllegalThenThrow(object value, ExceptionArgument argument) { + // Note that default(T) is not equal to null for value types except when T is Nullable. + if (!(default(T) == null) && value == null) + ThrowHelper.ThrowArgumentNullException(argument); + } - default: - Contract.Assert(false, "The enum value is not defined, please checked ExceptionArgumentName Enum."); - return string.Empty; - } + // + // This function will convert an ExceptionArgument enum value to the argument name string. + // + internal static string GetArgumentName(ExceptionArgument argument) + { + Contract.Assert(Enum.IsDefined(typeof(ExceptionArgument), argument), + "The enum value is not defined, please check the ExceptionArgument Enum."); - return argumentName; + return argument.ToString(); } // // This function will convert an ExceptionResource enum value to the resource string. // - internal static string GetResourceName(ExceptionResource resource) { - string resourceName = null; - - switch (resource) { - case ExceptionResource.Argument_ImplementIComparable: - resourceName = "Argument_ImplementIComparable"; - break; - - case ExceptionResource.Argument_AddingDuplicate: - resourceName = "Argument_AddingDuplicate"; - break; - - case ExceptionResource.ArgumentOutOfRange_BiggerThanCollection: - resourceName = "ArgumentOutOfRange_BiggerThanCollection"; - break; - - case ExceptionResource.ArgumentOutOfRange_Count: - resourceName = "ArgumentOutOfRange_Count"; - break; - - case ExceptionResource.ArgumentOutOfRange_Index: - resourceName = "ArgumentOutOfRange_Index"; - break; - - case ExceptionResource.ArgumentOutOfRange_InvalidThreshold: - resourceName = "ArgumentOutOfRange_InvalidThreshold"; - break; - - case ExceptionResource.ArgumentOutOfRange_ListInsert: - resourceName = "ArgumentOutOfRange_ListInsert"; - break; - - case ExceptionResource.ArgumentOutOfRange_NeedNonNegNum: - resourceName = "ArgumentOutOfRange_NeedNonNegNum"; - break; - - case ExceptionResource.ArgumentOutOfRange_SmallCapacity: - resourceName = "ArgumentOutOfRange_SmallCapacity"; - break; - - case ExceptionResource.Arg_ArrayPlusOffTooSmall: - resourceName = "Arg_ArrayPlusOffTooSmall"; - break; - - case ExceptionResource.Arg_RankMultiDimNotSupported: - resourceName = "Arg_RankMultiDimNotSupported"; - break; - - case ExceptionResource.Arg_NonZeroLowerBound: - resourceName = "Arg_NonZeroLowerBound"; - break; - - case ExceptionResource.Argument_InvalidArrayType: - resourceName = "Argument_InvalidArrayType"; - break; - - case ExceptionResource.Argument_InvalidOffLen: - resourceName = "Argument_InvalidOffLen"; - break; - - case ExceptionResource.Argument_ItemNotExist: - resourceName = "Argument_ItemNotExist"; - break; - - case ExceptionResource.InvalidOperation_CannotRemoveFromStackOrQueue: - resourceName = "InvalidOperation_CannotRemoveFromStackOrQueue"; - break; - - case ExceptionResource.InvalidOperation_EmptyQueue: - resourceName = "InvalidOperation_EmptyQueue"; - break; - - case ExceptionResource.InvalidOperation_EnumOpCantHappen: - resourceName = "InvalidOperation_EnumOpCantHappen"; - break; - - case ExceptionResource.InvalidOperation_EnumFailedVersion: - resourceName = "InvalidOperation_EnumFailedVersion"; - break; - - case ExceptionResource.InvalidOperation_EmptyStack: - resourceName = "InvalidOperation_EmptyStack"; - break; - - case ExceptionResource.InvalidOperation_EnumNotStarted: - resourceName = "InvalidOperation_EnumNotStarted"; - break; - - case ExceptionResource.InvalidOperation_EnumEnded: - resourceName = "InvalidOperation_EnumEnded"; - break; - - case ExceptionResource.NotSupported_KeyCollectionSet: - resourceName = "NotSupported_KeyCollectionSet"; - break; - - case ExceptionResource.NotSupported_ReadOnlyCollection: - resourceName = "NotSupported_ReadOnlyCollection"; - break; + internal static string GetResourceName(ExceptionResource resource) + { + Contract.Assert(Enum.IsDefined(typeof(ExceptionResource), resource), + "The enum value is not defined, please check the ExceptionResource Enum."); - case ExceptionResource.NotSupported_ValueCollectionSet: - resourceName = "NotSupported_ValueCollectionSet"; - break; - - - case ExceptionResource.NotSupported_SortedListNestedWrite: - resourceName = "NotSupported_SortedListNestedWrite"; - break; - - - case ExceptionResource.Serialization_InvalidOnDeser: - resourceName = "Serialization_InvalidOnDeser"; - break; - - case ExceptionResource.Serialization_MissingKeys: - resourceName = "Serialization_MissingKeys"; - break; - - case ExceptionResource.Serialization_NullKey: - resourceName = "Serialization_NullKey"; - break; - - case ExceptionResource.Argument_InvalidType: - resourceName = "Argument_InvalidType"; - break; - - case ExceptionResource.Argument_InvalidArgumentForComparison: - resourceName = "Argument_InvalidArgumentForComparison"; - break; - - case ExceptionResource.InvalidOperation_NoValue: - resourceName = "InvalidOperation_NoValue"; - break; - - case ExceptionResource.InvalidOperation_RegRemoveSubKey: - resourceName = "InvalidOperation_RegRemoveSubKey"; - break; - - case ExceptionResource.Arg_RegSubKeyAbsent: - resourceName = "Arg_RegSubKeyAbsent"; - break; - - case ExceptionResource.Arg_RegSubKeyValueAbsent: - resourceName = "Arg_RegSubKeyValueAbsent"; - break; - - case ExceptionResource.Arg_RegKeyDelHive: - resourceName = "Arg_RegKeyDelHive"; - break; - - case ExceptionResource.Security_RegistryPermission: - resourceName = "Security_RegistryPermission"; - break; - - case ExceptionResource.Arg_RegSetStrArrNull: - resourceName = "Arg_RegSetStrArrNull"; - break; - - case ExceptionResource.Arg_RegSetMismatchedKind: - resourceName = "Arg_RegSetMismatchedKind"; - break; - - case ExceptionResource.UnauthorizedAccess_RegistryNoWrite: - resourceName = "UnauthorizedAccess_RegistryNoWrite"; - break; - - case ExceptionResource.ObjectDisposed_RegKeyClosed: - resourceName = "ObjectDisposed_RegKeyClosed"; - break; - - case ExceptionResource.Arg_RegKeyStrLenBug: - resourceName = "Arg_RegKeyStrLenBug"; - break; - - case ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck: - resourceName = "Argument_InvalidRegistryKeyPermissionCheck"; - break; - - case ExceptionResource.NotSupported_InComparableType: - resourceName = "NotSupported_InComparableType"; - break; - - case ExceptionResource.Argument_InvalidRegistryOptionsCheck: - resourceName = "Argument_InvalidRegistryOptionsCheck"; - break; - - case ExceptionResource.Argument_InvalidRegistryViewCheck: - resourceName = "Argument_InvalidRegistryViewCheck"; - break; - - default: - Contract.Assert( false, "The enum value is not defined, please checked ExceptionArgumentName Enum."); - return string.Empty; - } - - return resourceName; + return resource.ToString(); } - } // @@ -467,7 +250,67 @@ internal enum ExceptionArgument { view, sourceBytesToCopy, action, - comparison + comparison, + keys, + elementType, + newSize, + len, + length, + length1, + length2, + length3, + lengths, + sourceIndex, + destinationIndex, + index1, + index2, + index3, + indices, + offset, + lowerBounds, + sourceArray, + destinationArray, + comparer, + endIndex, + other, + function, + scheduler, + continuationAction, + creationOptions, + observer, + continuationFunction, + valueFactory, + handler, + typeName, + culture, + addValueFactory, + updateValueFactory, + concurrencyLevel, + items, + source, + partitionerOptions, + toExclusive, + rangeSize, + partitionCount, + SymWriter, + path, + buffer, + asyncResult, + bufferSize, + access, + share, + endMethod, + beginMethod, + endFunction, + tasks, + exception, + timeout, + millisecondsTimeout, + cancellationToken, + continuationOptions, + delay, + millisecondsDelay, + exceptions, } // @@ -521,7 +364,97 @@ internal enum ExceptionResource { ObjectDisposed_RegKeyClosed, NotSupported_InComparableType, Argument_InvalidRegistryOptionsCheck, - Argument_InvalidRegistryViewCheck + Argument_InvalidRegistryViewCheck, + + InvalidOperation_IComparerFailed, + ArgumentOutOfRange_HugeArrayNotSupported, + NotSupported_FixedSizeCollection, + Arg_MustBeType, + InvalidOperation_NullArray, + Arg_NeedAtLeast1Rank, + Arg_RanksAndBounds, + Arg_RankIndices, + Arg_Need1DArray, + Arg_Need2DArray, + Arg_Need3DArray, + ArgumentException_OtherNotArrayOfCorrectLength, + Rank_MultiDimNotSupported, + ArgumentOutOfRange_EndIndexStartIndex, + Arg_LowerBoundsMustMatch, + Arg_BogusIComparer, + + Arg_WrongType, + Argument_AddingDuplicateWithKey, + + TaskT_ctor_SelfReplicating, + + Lazy_ctor_ModeInvalid, + Lazy_Value_RecursiveCallsToValue, + + ConcurrentDictionary_SourceContainsDuplicateKeys, + ConcurrentDictionary_ArrayNotLargeEnough, + ConcurrentDictionary_KeyAlreadyExisted, + ConcurrentDictionary_TypeOfKeyIncorrect, + ConcurrentDictionary_TypeOfValueIncorrect, + ConcurrentDictionary_ArrayIncorrectType, + ConcurrentCollection_SyncRoot_NotSupported, + ConcurrentDictionary_ConcurrencyLevelMustBePositive, + ConcurrentDictionary_CapacityMustNotBeNegative, + ConcurrentDictionary_IndexIsNegative, + ConcurrentDictionary_ItemKeyIsNull, + + ConcurrentStack_PushPopRange_InvalidCount, + ConcurrentStack_PushPopRange_CountOutOfRange, + ConcurrentStack_PushPopRange_StartOutOfRange, + + Partitioner_DynamicPartitionsNotSupported, + OrderablePartitioner_GetPartitions_WrongNumberOfPartitions, + PartitionerStatic_CanNotCallGetEnumeratorAfterSourceHasBeenDisposed, + PartitionerStatic_CurrentCalledBeforeMoveNext, + + NotSupported_Constructor, + Format_NeedSingleChar, + NotSupported_Method, + Argument_UnclosedExceptionBlock, + InvalidOperation_AssemblyHasBeenSaved, + MissingType, + Serialization_InsufficientState, + Serialization_NullSignature, + Serialization_BadParameterInfo, + Serialization_NoParameterInfo, + Serialization_UnknownMember, + + InvalidOperation_WithoutARM, + + ArgumentNull_Path, + Argument_EmptyPath, + ArgumentNull_Buffer, + ArgumentOutOfRange_Enum, + ArgumentOutOfRange_NeedPosNum, + + Task_MultiTaskContinuation_EmptyTaskList, + InvalidOperation_WrongAsyncResultOrEndCalledMultiple, + Task_MultiTaskContinuation_NullTask, + Task_Start_TaskCompleted, + Task_Start_Promise, + Task_Start_ContinuationTask, + Task_Start_AlreadyStarted, + Task_Dispose_NotCompleted, + Task_RunSynchronously_TaskCompleted, + Task_RunSynchronously_Continuation, + Task_RunSynchronously_Promise, + Task_RunSynchronously_AlreadyStarted, + Task_ctor_LRandSR, + Task_ThrowIfDisposed, + Task_WaitMulti_NullTask, + Task_ContinueWith_NotOnAnything, + Task_ContinueWith_ESandLR, + Task_Delay_InvalidDelay, + Task_Delay_InvalidMillisecondsDelay, + TaskT_TransitionToFinal_AlreadyCompleted, + TaskCompletionSourceT_TrySetException_NullException, + TaskCompletionSourceT_TrySetException_NoExceptions + } } diff --git a/src/mscorlib/src/System/WeakReferenceOfT.cs b/src/mscorlib/src/System/WeakReferenceOfT.cs index b8195df6d9d2..384c2044888e 100644 --- a/src/mscorlib/src/System/WeakReferenceOfT.cs +++ b/src/mscorlib/src/System/WeakReferenceOfT.cs @@ -46,7 +46,7 @@ public WeakReference(T target, bool trackResurrection) internal WeakReference(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info); } Contract.EndContractBlock(); @@ -102,7 +102,7 @@ private extern T Target public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info); } Contract.EndContractBlock();