diff options
Diffstat (limited to 'src/mscorlib/src/System/BitConverter.cs')
-rw-r--r-- | src/mscorlib/src/System/BitConverter.cs | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/src/mscorlib/src/System/BitConverter.cs b/src/mscorlib/src/System/BitConverter.cs index e4bb9ddc88..3a6d1c03b0 100644 --- a/src/mscorlib/src/System/BitConverter.cs +++ b/src/mscorlib/src/System/BitConverter.cs @@ -15,6 +15,7 @@ namespace System { using System; using System.Runtime.CompilerServices; + using System.Diagnostics; using System.Diagnostics.Contracts; using System.Security; @@ -56,7 +57,6 @@ namespace System { // Converts a short into an array of bytes with length // two. - [System.Security.SecuritySafeCritical] // auto-generated public unsafe static byte[] GetBytes(short value) { Contract.Ensures(Contract.Result<byte[]>() != null); @@ -70,7 +70,6 @@ namespace System { // Converts an int into an array of bytes with length // four. - [System.Security.SecuritySafeCritical] // auto-generated public unsafe static byte[] GetBytes(int value) { Contract.Ensures(Contract.Result<byte[]>() != null); @@ -84,7 +83,6 @@ namespace System { // Converts a long into an array of bytes with length // eight. - [System.Security.SecuritySafeCritical] // auto-generated public unsafe static byte[] GetBytes(long value) { Contract.Ensures(Contract.Result<byte[]>() != null); @@ -128,7 +126,6 @@ namespace System { // Converts a float into an array of bytes with length // four. - [System.Security.SecuritySafeCritical] // auto-generated public unsafe static byte[] GetBytes(float value) { Contract.Ensures(Contract.Result<byte[]>() != null); @@ -139,7 +136,6 @@ namespace System { // Converts a double into an array of bytes with length // eight. - [System.Security.SecuritySafeCritical] // auto-generated public unsafe static byte[] GetBytes(double value) { Contract.Ensures(Contract.Result<byte[]>() != null); @@ -156,7 +152,7 @@ namespace System { } if ((uint)startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length - 2) { @@ -168,14 +164,13 @@ namespace System { } // Converts an array of bytes into a short. - [System.Security.SecuritySafeCritical] // auto-generated public static unsafe short ToInt16(byte[] value, int startIndex) { if( value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -2) { @@ -200,14 +195,13 @@ namespace System { } // Converts an array of bytes into an int. - [System.Security.SecuritySafeCritical] // auto-generated public static unsafe int ToInt32 (byte[] value, int startIndex) { if( value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -4) { @@ -231,14 +225,13 @@ namespace System { } // Converts an array of bytes into a long. - [System.Security.SecuritySafeCritical] // auto-generated public static unsafe long ToInt64 (byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint) startIndex >= value.Length) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } if (startIndex > value.Length -8) { @@ -274,7 +267,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 2) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -290,7 +283,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 4) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -306,7 +299,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 8) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -315,13 +308,12 @@ namespace System { } // Converts an array of bytes into a float. - [System.Security.SecuritySafeCritical] // auto-generated unsafe public static float ToSingle (byte[] value, int startIndex) { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 4) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -331,13 +323,12 @@ namespace System { } // Converts an array of bytes into a double. - [System.Security.SecuritySafeCritical] // auto-generated unsafe public static double ToDouble (byte[] value, int startIndex) { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if ((uint)startIndex >= value.Length) - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); if (startIndex > value.Length - 8) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); Contract.EndContractBlock(); @@ -347,7 +338,7 @@ namespace System { } private static char GetHexValue(int i) { - Contract.Assert( i >=0 && i <16, "i is out of range."); + Debug.Assert( i >=0 && i <16, "i is out of range."); if (i<10) { return (char)(i + '0'); } @@ -358,15 +349,15 @@ namespace System { // Converts an array of bytes into a String. public static String ToString (byte[] value, int startIndex, int length) { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (startIndex < 0 || startIndex >= value.Length && startIndex > 0) { // Don't throw for a 0 length array. - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if (startIndex > value.Length - length) { @@ -380,7 +371,7 @@ namespace System { if (length > (Int32.MaxValue / 3)) { // (Int32.MaxValue / 3) == 715,827,882 Bytes == 699 MB - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_LengthTooLarge", (Int32.MaxValue / 3))); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_LengthTooLarge", (Int32.MaxValue / 3))); } int chArrayLength = length * 3; @@ -402,7 +393,7 @@ namespace System { // Converts an array of bytes into a String. public static String ToString(byte [] value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); return ToString(value, 0, value.Length); @@ -411,7 +402,7 @@ namespace System { // Converts an array of bytes into a String. public static String ToString (byte [] value, int startIndex) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); return ToString(value, startIndex, value.Length - startIndex); @@ -428,24 +419,30 @@ namespace System { // Converts an array of bytes into a boolean. public static bool ToBoolean(byte[] value, int startIndex) { if (value==null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (startIndex > value.Length - 1) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return (value[startIndex]==0)?false:true; } - [SecuritySafeCritical] public static unsafe long DoubleToInt64Bits(double value) { return *((long *)&value); } - [SecuritySafeCritical] public static unsafe double Int64BitsToDouble(long value) { return *((double*)&value); - } + } + + public static unsafe int SingleToInt32Bits(float value) { + return *((int*)&value); + } + + public static unsafe float Int32BitsToSingle(int value) { + return *((float*)&value); + } } } |