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