<Compile Include="$(BclSourcesRoot)\System\ArgIterator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Attribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\BadImageFormatException.CoreCLR.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Boolean.cs" />
<Compile Include="$(BclSourcesRoot)\System\Buffer.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Byte.cs" />
<Compile Include="$(BclSourcesRoot)\System\CompatibilitySwitches.cs" />
<Compile Include="$(BclSourcesRoot)\System\Currency.cs" />
<Compile Include="$(BclSourcesRoot)\System\Decimal.cs" />
<Compile Include="$(BclSourcesRoot)\System\GC.cs" />
<Compile Include="$(BclSourcesRoot)\System\Guid.cs" />
<Compile Include="$(BclSourcesRoot)\System\InsufficientMemoryException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Int16.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Int32.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Int64.cs" />
<Compile Include="$(BclSourcesRoot)\System\IntPtr.cs" />
<Compile Include="$(BclSourcesRoot)\System\Internal.cs" />
<Compile Include="$(BclSourcesRoot)\System\Math.cs" />
<Compile Include="$(BclSourcesRoot)\System\RtType.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeArgumentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" />
- <Compile Include="$(BclSourcesRoot)\System\SByte.cs" />
<Compile Include="$(BclSourcesRoot)\System\SerializableAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\SharedStatics.cs" />
<Compile Include="$(BclSourcesRoot)\System\StubHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeNameParser.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\UInt16.cs" />
- <Compile Include="$(BclSourcesRoot)\System\UInt32.cs" />
- <Compile Include="$(BclSourcesRoot)\System\UInt64.cs" />
<Compile Include="$(BclSourcesRoot)\System\UIntPtr.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
<Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\AttributeUsageAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\BadImageFormatException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\BitConverter.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Boolean.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ArrayPool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ArrayPoolEventSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\ConfigurableArrayPool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\TlsOverPerCoreLockedStacksArrayPool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Utilities.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Byte.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Char.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\CharEnumerator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\CLSCompliantAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IObservable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IObserver.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IProgress.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Int16.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Int32.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Int64.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Lazy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\MarshalByRefObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\MemberAccessException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\StreamingContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\NonVersionableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\TargetFrameworkAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\SByte.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\AllowPartiallyTrustedCallersAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\CryptographicException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\PartialTrustVisibilityLevel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeCode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeInitializationException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TypeUnloadedException.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\UInt16.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\UInt32.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\UInt64.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\UnauthorizedAccessException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventHandler.cs" />
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: The boolean class serves as a wrapper for the primitive
+** type boolean.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct Boolean : IComparable, IConvertible, IComparable<Boolean>, IEquatable<Boolean>
+ {
+ //
+ // Member Variables
+ //
+ private bool m_value; // Do not rename (binary serialization)
+
+ // The true value.
+ //
+ internal const int True = 1;
+
+ // The false value.
+ //
+ internal const int False = 0;
+
+
+ //
+ // Internal Constants are real consts for performance.
+ //
+
+ // The internal string representation of true.
+ //
+ internal const String TrueLiteral = "True";
+
+ // The internal string representation of false.
+ //
+ internal const String FalseLiteral = "False";
+
+
+ //
+ // Public Constants
+ //
+
+ // The public string representation of true.
+ //
+ public static readonly String TrueString = TrueLiteral;
+
+ // The public string representation of false.
+ //
+ public static readonly String FalseString = FalseLiteral;
+
+ //
+ // Overriden Instance Methods
+ //
+ /*=================================GetHashCode==================================
+ **Args: None
+ **Returns: 1 or 0 depending on whether this instance represents true or false.
+ **Exceptions: None
+ **Overriden From: Value
+ ==============================================================================*/
+ // Provides a hash code for this instance.
+ public override int GetHashCode()
+ {
+ return (m_value) ? True : False;
+ }
+
+ /*===================================ToString===================================
+ **Args: None
+ **Returns: "True" or "False" depending on the state of the boolean.
+ **Exceptions: None.
+ ==============================================================================*/
+ // Converts the boolean value of this instance to a String.
+ public override String ToString()
+ {
+ if (false == m_value)
+ {
+ return FalseLiteral;
+ }
+ return TrueLiteral;
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ return ToString();
+ }
+
+ // Determines whether two Boolean objects are equal.
+ public override bool Equals(Object obj)
+ {
+ //If it's not a boolean, we're definitely not equal
+ if (!(obj is Boolean))
+ {
+ return false;
+ }
+
+ return (m_value == ((Boolean)obj).m_value);
+ }
+
+ [NonVersionable]
+ public bool Equals(Boolean obj)
+ {
+ return m_value == obj;
+ }
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship. For booleans, false sorts before true.
+ // null is considered to be less than any instance.
+ // If object is not of type boolean, this method throws an ArgumentException.
+ //
+ // Returns a value less than zero if this object
+ //
+ public int CompareTo(Object obj)
+ {
+ if (obj == null)
+ {
+ return 1;
+ }
+ if (!(obj is Boolean))
+ {
+ throw new ArgumentException(SR.Arg_MustBeBoolean);
+ }
+
+ if (m_value == ((Boolean)obj).m_value)
+ {
+ return 0;
+ }
+ else if (m_value == false)
+ {
+ return -1;
+ }
+ return 1;
+ }
+
+ public int CompareTo(Boolean value)
+ {
+ if (m_value == value)
+ {
+ return 0;
+ }
+ else if (m_value == false)
+ {
+ return -1;
+ }
+ return 1;
+ }
+
+ //
+ // Static Methods
+ //
+
+ // Determines whether a String represents true or false.
+ //
+ public static Boolean Parse(String value)
+ {
+ if (value == null) throw new ArgumentNullException(nameof(value));
+ Contract.EndContractBlock();
+ Boolean result = false;
+ if (!TryParse(value, out result))
+ {
+ throw new FormatException(SR.Format_BadBoolean);
+ }
+ else
+ {
+ return result;
+ }
+ }
+
+ // Determines whether a String represents true or false.
+ //
+ public static Boolean TryParse(String value, out Boolean result)
+ {
+ result = false;
+ if (value == null)
+ {
+ return false;
+ }
+ // For perf reasons, let's first see if they're equal, then do the
+ // trim to get rid of white space, and check again.
+ if (TrueLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
+ {
+ result = true;
+ return true;
+ }
+ if (FalseLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
+ {
+ result = false;
+ return true;
+ }
+
+ // Special case: Trim whitespace as well as null characters.
+ value = TrimWhiteSpaceAndNull(value);
+
+ if (TrueLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
+ {
+ result = true;
+ return true;
+ }
+
+ if (FalseLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
+ {
+ result = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ private static String TrimWhiteSpaceAndNull(String value)
+ {
+ int start = 0;
+ int end = value.Length - 1;
+ char nullChar = (char)0x0000;
+
+ while (start < value.Length)
+ {
+ if (!Char.IsWhiteSpace(value[start]) && value[start] != nullChar)
+ {
+ break;
+ }
+ start++;
+ }
+
+ while (end >= start)
+ {
+ if (!Char.IsWhiteSpace(value[end]) && value[end] != nullChar)
+ {
+ break;
+ }
+ end--;
+ }
+
+ return value.Substring(start, end - start + 1);
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.Boolean;
+ }
+
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "Char"));
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: This class will encapsulate a byte and provide an
+** Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct Byte : IComparable, IConvertible, IFormattable, IComparable<Byte>, IEquatable<Byte>
+ {
+ private byte m_value; // Do not rename (binary serialization)
+
+ // The maximum value that a Byte may represent: 255.
+ public const byte MaxValue = (byte)0xFF;
+
+ // The minimum value that a Byte may represent: 0.
+ public const byte MinValue = 0;
+
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type byte, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (!(value is Byte))
+ {
+ throw new ArgumentException(SR.Arg_MustBeByte);
+ }
+
+ return m_value - (((Byte)value).m_value);
+ }
+
+ public int CompareTo(Byte value)
+ {
+ return m_value - value;
+ }
+
+ // Determines whether two Byte objects are equal.
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is Byte))
+ {
+ return false;
+ }
+ return m_value == ((Byte)obj).m_value;
+ }
+
+ [NonVersionable]
+ public bool Equals(Byte obj)
+ {
+ return m_value == obj;
+ }
+
+ // Gets a hash code for this instance.
+ public override int GetHashCode()
+ {
+ return m_value;
+ }
+
+ [Pure]
+ public static byte Parse(String s)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public static byte Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public static byte Parse(String s, IFormatProvider provider)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+
+ // Parses an unsigned byte from a String in the given style. If
+ // a NumberFormatInfo isn't specified, the current culture's
+ // NumberFormatInfo is assumed.
+ [Pure]
+ public static byte Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private static byte Parse(String s, NumberStyles style, NumberFormatInfo info)
+ {
+ int i = 0;
+ try
+ {
+ i = Number.ParseInt32(s, style, info);
+ }
+ catch (OverflowException e)
+ {
+ throw new OverflowException(SR.Overflow_Byte, e);
+ }
+
+ if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_Byte);
+ return (byte)i;
+ }
+
+ public static bool TryParse(String s, out Byte result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Byte result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out Byte result)
+ {
+ result = 0;
+ int i;
+ if (!Number.TryParseInt32(s, style, info, out i))
+ {
+ return false;
+ }
+ if (i < MinValue || i > MaxValue)
+ {
+ return false;
+ }
+ result = (byte)i;
+ return true;
+ }
+
+ [Pure]
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [Pure]
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ //
+ // IConvertible implementation
+ //
+ [Pure]
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.Byte;
+ }
+
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Byte", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
**
===========================================================*/
-using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
[Serializable]
[StructLayout(LayoutKind.Sequential)]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Double :IComparable, IConvertible, IFormattable, IComparable<Double>, IEquatable<Double>
+ public struct Double : IComparable, IConvertible, IFormattable, IComparable<Double>, IEquatable<Double>
{
private double m_value; // Do not rename (binary serialization)
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: This class will encapsulate a short and provide an
+** Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct Int16 : IComparable, IConvertible, IFormattable, IComparable<Int16>, IEquatable<Int16>
+ {
+ private short m_value; // Do not rename (binary serialization)
+
+ public const short MaxValue = (short)0x7FFF;
+ public const short MinValue = unchecked((short)0x8000);
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type Int16, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+
+ if (value is Int16)
+ {
+ return m_value - ((Int16)value).m_value;
+ }
+
+ throw new ArgumentException(SR.Arg_MustBeInt16);
+ }
+
+ public int CompareTo(Int16 value)
+ {
+ return m_value - value;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is Int16))
+ {
+ return false;
+ }
+ return m_value == ((Int16)obj).m_value;
+ }
+
+ [NonVersionable]
+ public bool Equals(Int16 obj)
+ {
+ return m_value == obj;
+ }
+
+ // Returns a HashCode for the Int16
+ public override int GetHashCode()
+ {
+ return ((int)((ushort)m_value) | (((int)m_value) << 16));
+ }
+
+
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return ToString(format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return ToString(format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private String ToString(String format, NumberFormatInfo info)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+
+ if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
+ {
+ uint temp = (uint)(m_value & 0x0000FFFF);
+ return Number.FormatUInt32(temp, format, info);
+ }
+ return Number.FormatInt32(m_value, format, info);
+ }
+
+ public static short Parse(String s)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ public static short Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ public static short Parse(String s, IFormatProvider provider)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public static short Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private static short Parse(String s, NumberStyles style, NumberFormatInfo info)
+ {
+ int i = 0;
+ try
+ {
+ i = Number.ParseInt32(s, style, info);
+ }
+ catch (OverflowException e)
+ {
+ throw new OverflowException(SR.Overflow_Int16, e);
+ }
+
+ // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
+ // for negative numbers
+ if ((style & NumberStyles.AllowHexSpecifier) != 0)
+ { // We are parsing a hexadecimal number
+ if ((i < 0) || (i > UInt16.MaxValue))
+ {
+ throw new OverflowException(SR.Overflow_Int16);
+ }
+ return (short)i;
+ }
+
+ if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_Int16);
+ return (short)i;
+ }
+
+ public static bool TryParse(String s, out Int16 result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int16 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out Int16 result)
+ {
+ result = 0;
+ int i;
+ if (!Number.TryParseInt32(s, style, info, out i))
+ {
+ return false;
+ }
+
+ // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
+ // for negative numbers
+ if ((style & NumberStyles.AllowHexSpecifier) != 0)
+ { // We are parsing a hexadecimal number
+ if ((i < 0) || i > UInt16.MaxValue)
+ {
+ return false;
+ }
+ result = (Int16)i;
+ return true;
+ }
+
+ if (i < MinValue || i > MaxValue)
+ {
+ return false;
+ }
+ result = (Int16)i;
+ return true;
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.Int16;
+ }
+
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: A representation of a 32 bit 2's complement
+** integer.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct Int32 : IComparable, IConvertible, IFormattable, IComparable<Int32>, IEquatable<Int32>
+ {
+ private int m_value; // Do not rename (binary serialization)
+
+ public const int MaxValue = 0x7fffffff;
+ public const int MinValue = unchecked((int)0x80000000);
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns :
+ // 0 if the values are equal
+ // Negative number if _value is less than value
+ // Positive number if _value is more than value
+ // null is considered to be less than any instance, hence returns positive number
+ // If object is not of type Int32, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (value is Int32)
+ {
+ // NOTE: Cannot use return (_value - value) as this causes a wrap
+ // around in cases where _value - value > MaxValue.
+ int i = (int)value;
+ if (m_value < i) return -1;
+ if (m_value > i) return 1;
+ return 0;
+ }
+ throw new ArgumentException(SR.Arg_MustBeInt32);
+ }
+
+ public int CompareTo(int value)
+ {
+ // NOTE: Cannot use return (_value - value) as this causes a wrap
+ // around in cases where _value - value > MaxValue.
+ if (m_value < value) return -1;
+ if (m_value > value) return 1;
+ return 0;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is Int32))
+ {
+ return false;
+ }
+ return m_value == ((Int32)obj).m_value;
+ }
+
+ [NonVersionable]
+ public bool Equals(Int32 obj)
+ {
+ return m_value == obj;
+ }
+
+ // The absolute value of the int contained.
+ public override int GetHashCode()
+ {
+ return m_value;
+ }
+
+ [Pure]
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [Pure]
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [Pure]
+ public static int Parse(String s)
+ {
+ return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [Pure]
+ public static int Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ // Parses an integer from a String in the given style. If
+ // a NumberFormatInfo isn't specified, the current culture's
+ // NumberFormatInfo is assumed.
+ //
+ [Pure]
+ public static int Parse(String s, IFormatProvider provider)
+ {
+ return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ // Parses an integer from a String in the given style. If
+ // a NumberFormatInfo isn't specified, the current culture's
+ // NumberFormatInfo is assumed.
+ //
+ [Pure]
+ public static int Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ // Parses an integer from a String. Returns false rather
+ // than throwing exceptin if input is invalid
+ //
+ [Pure]
+ public static bool TryParse(String s, out Int32 result)
+ {
+ return Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ // Parses an integer from a String in the given style. Returns false rather
+ // than throwing exceptin if input is invalid
+ //
+ [Pure]
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ [Pure]
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.Int32;
+ }
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int32", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: This class will encapsulate a long and provide an
+** Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct Int64 : IComparable, IConvertible, IFormattable, IComparable<Int64>, IEquatable<Int64>
+ {
+ private long m_value; // Do not rename (binary serialization)
+
+ public const long MaxValue = 0x7fffffffffffffffL;
+ public const long MinValue = unchecked((long)0x8000000000000000L);
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type Int64, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (value is Int64)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ long i = (long)value;
+ if (m_value < i) return -1;
+ if (m_value > i) return 1;
+ return 0;
+ }
+ throw new ArgumentException(SR.Arg_MustBeInt64);
+ }
+
+ public int CompareTo(Int64 value)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (m_value < value) return -1;
+ if (m_value > value) return 1;
+ return 0;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is Int64))
+ {
+ return false;
+ }
+ return m_value == ((Int64)obj).m_value;
+ }
+
+ [System.Runtime.Versioning.NonVersionable]
+ public bool Equals(Int64 obj)
+ {
+ return m_value == obj;
+ }
+
+ // The value of the lower 32 bits XORed with the uppper 32 bits.
+ public override int GetHashCode()
+ {
+ return (unchecked((int)((long)m_value)) ^ (int)(m_value >> 32));
+ }
+
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt64(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt64(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt64(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt64(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public static long Parse(String s)
+ {
+ return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ public static long Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseInt64(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ public static long Parse(String s, IFormatProvider provider)
+ {
+ return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+
+ // Parses a long from a String in the given style. If
+ // a NumberFormatInfo isn't specified, the current culture's
+ // NumberFormatInfo is assumed.
+ //
+ public static long Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseInt64(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public static Boolean TryParse(String s, out Int64 result)
+ {
+ return Number.TryParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Int64 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.TryParseInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.Int64;
+ }
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int64", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [CLSCompliant(false)] [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct SByte : IComparable, IConvertible, IFormattable, IComparable<SByte>, IEquatable<SByte>
+ {
+ private sbyte m_value; // Do not rename (binary serialization)
+
+ // The maximum value that a Byte may represent: 127.
+ public const sbyte MaxValue = (sbyte)0x7F;
+
+ // The minimum value that a Byte may represent: -128.
+ public const sbyte MinValue = unchecked((sbyte)0x80);
+
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type SByte, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object obj)
+ {
+ if (obj == null)
+ {
+ return 1;
+ }
+ if (!(obj is SByte))
+ {
+ throw new ArgumentException(SR.Arg_MustBeSByte);
+ }
+ return m_value - ((SByte)obj).m_value;
+ }
+
+ public int CompareTo(SByte value)
+ {
+ return m_value - value;
+ }
+
+ // Determines whether two Byte objects are equal.
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is SByte))
+ {
+ return false;
+ }
+ return m_value == ((SByte)obj).m_value;
+ }
+
+ [NonVersionable]
+ public bool Equals(SByte obj)
+ {
+ return m_value == obj;
+ }
+
+ // Gets a hash code for this instance.
+ public override int GetHashCode()
+ {
+ return ((int)m_value ^ (int)m_value << 8);
+ }
+
+
+ // Provides a string representation of a byte.
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return ToString(format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return ToString(format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private String ToString(String format, NumberFormatInfo info)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+
+ if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
+ {
+ uint temp = (uint)(m_value & 0x000000FF);
+ return Number.FormatUInt32(temp, format, info);
+ }
+ return Number.FormatInt32(m_value, format, info);
+ }
+
+ [CLSCompliant(false)]
+ public static sbyte Parse(String s)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static sbyte Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static sbyte Parse(String s, IFormatProvider provider)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ // Parses a signed byte from a String in the given style. If
+ // a NumberFormatInfo isn't specified, the current culture's
+ // NumberFormatInfo is assumed.
+ //
+ [CLSCompliant(false)]
+ public static sbyte Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private static sbyte Parse(String s, NumberStyles style, NumberFormatInfo info)
+ {
+ int i = 0;
+ try
+ {
+ i = Number.ParseInt32(s, style, info);
+ }
+ catch (OverflowException e)
+ {
+ throw new OverflowException(SR.Overflow_SByte, e);
+ }
+
+ if ((style & NumberStyles.AllowHexSpecifier) != 0)
+ { // We are parsing a hexadecimal number
+ if ((i < 0) || i > Byte.MaxValue)
+ {
+ throw new OverflowException(SR.Overflow_SByte);
+ }
+ return (sbyte)i;
+ }
+
+ if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_SByte);
+ return (sbyte)i;
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, out SByte result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out SByte result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out SByte result)
+ {
+ result = 0;
+ int i;
+ if (!Number.TryParseInt32(s, style, info, out i))
+ {
+ return false;
+ }
+
+ if ((style & NumberStyles.AllowHexSpecifier) != 0)
+ { // We are parsing a hexadecimal number
+ if ((i < 0) || i > Byte.MaxValue)
+ {
+ return false;
+ }
+ result = (sbyte)i;
+ return true;
+ }
+
+ if (i < MinValue || i > MaxValue)
+ {
+ return false;
+ }
+ result = (sbyte)i;
+ return true;
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.SByte;
+ }
+
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
**
===========================================================*/
-using System;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+** Purpose: This class will encapsulate a short and provide an
+** Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [CLSCompliant(false)]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct UInt16 : IComparable, IConvertible, IFormattable, IComparable<UInt16>, IEquatable<UInt16>
+ {
+ private ushort m_value; // Do not rename (binary serialization)
+
+ public const ushort MaxValue = (ushort)0xFFFF;
+ public const ushort MinValue = 0;
+
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type UInt16, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (value is UInt16)
+ {
+ return ((int)m_value - (int)(((UInt16)value).m_value));
+ }
+ throw new ArgumentException(SR.Arg_MustBeUInt16);
+ }
+
+ public int CompareTo(UInt16 value)
+ {
+ return ((int)m_value - (int)value);
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is UInt16))
+ {
+ return false;
+ }
+ return m_value == ((UInt16)obj).m_value;
+ }
+
+ [System.Runtime.Versioning.NonVersionable]
+ public bool Equals(UInt16 obj)
+ {
+ return m_value == obj;
+ }
+
+ // Returns a HashCode for the UInt16
+ public override int GetHashCode()
+ {
+ return (int)m_value;
+ }
+
+ // Converts the current value to a String in base-10 with no extra padding.
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static ushort Parse(String s)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static ushort Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+
+ [CLSCompliant(false)]
+ public static ushort Parse(String s, IFormatProvider provider)
+ {
+ return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static ushort Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Parse(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ private static ushort Parse(String s, NumberStyles style, NumberFormatInfo info)
+ {
+ uint i = 0;
+ try
+ {
+ i = Number.ParseUInt32(s, style, info);
+ }
+ catch (OverflowException e)
+ {
+ throw new OverflowException(SR.Overflow_UInt16, e);
+ }
+
+ if (i > MaxValue) throw new OverflowException(SR.Overflow_UInt16);
+ return (ushort)i;
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, out UInt16 result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt16 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out UInt16 result)
+ {
+ result = 0;
+ UInt32 i;
+ if (!Number.TryParseUInt32(s, style, info, out i))
+ {
+ return false;
+ }
+ if (i > MaxValue)
+ {
+ return false;
+ }
+ result = (UInt16)i;
+ return true;
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.UInt16;
+ }
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+**
+** Purpose: This class will encapsulate an uint and
+** provide an Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [CLSCompliant(false)]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct UInt32 : IComparable, IConvertible, IFormattable, IComparable<UInt32>, IEquatable<UInt32>
+ {
+ private uint m_value; // Do not rename (binary serialization)
+
+ public const uint MaxValue = (uint)0xffffffff;
+ public const uint MinValue = 0U;
+
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type UInt32, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (value is UInt32)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ uint i = (uint)value;
+ if (m_value < i) return -1;
+ if (m_value > i) return 1;
+ return 0;
+ }
+ throw new ArgumentException(SR.Arg_MustBeUInt32);
+ }
+
+ public int CompareTo(UInt32 value)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (m_value < value) return -1;
+ if (m_value > value) return 1;
+ return 0;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is UInt32))
+ {
+ return false;
+ }
+ return m_value == ((UInt32)obj).m_value;
+ }
+
+ [System.Runtime.Versioning.NonVersionable]
+ public bool Equals(UInt32 obj)
+ {
+ return m_value == obj;
+ }
+
+ // The absolute value of the int contained.
+ public override int GetHashCode()
+ {
+ return ((int)m_value);
+ }
+
+ // The base 10 representation of the number with no extra padding.
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static uint Parse(String s)
+ {
+ return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static uint Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseUInt32(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+
+ [CLSCompliant(false)]
+ public static uint Parse(String s, IFormatProvider provider)
+ {
+ return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static uint Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseUInt32(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, out UInt32 result)
+ {
+ return Number.TryParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
+ public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt32 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.TryParseUInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.UInt32;
+ }
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return Convert.ToUInt64(m_value);
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt32", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================
+**
+**
+** Purpose: This class will encapsulate an unsigned long and
+** provide an Object representation of it.
+**
+**
+===========================================================*/
+
+using System.Diagnostics.Contracts;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
+
+namespace System
+{
+ [Serializable]
+ [CLSCompliant(false)]
+ [StructLayout(LayoutKind.Sequential)]
+ [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+ public struct UInt64 : IComparable, IConvertible, IFormattable, IComparable<UInt64>, IEquatable<UInt64>
+ {
+ private ulong m_value; // Do not rename (binary serialization)
+
+ public const ulong MaxValue = (ulong)0xffffffffffffffffL;
+ public const ulong MinValue = 0x0;
+
+ // Compares this object to another object, returning an integer that
+ // indicates the relationship.
+ // Returns a value less than zero if this object
+ // null is considered to be less than any instance.
+ // If object is not of type UInt64, this method throws an ArgumentException.
+ //
+ public int CompareTo(Object value)
+ {
+ if (value == null)
+ {
+ return 1;
+ }
+ if (value is UInt64)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ ulong i = (ulong)value;
+ if (m_value < i) return -1;
+ if (m_value > i) return 1;
+ return 0;
+ }
+ throw new ArgumentException(SR.Arg_MustBeUInt64);
+ }
+
+ public int CompareTo(UInt64 value)
+ {
+ // Need to use compare because subtraction will wrap
+ // to positive for very large neg numbers, etc.
+ if (m_value < value) return -1;
+ if (m_value > value) return 1;
+ return 0;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if (!(obj is UInt64))
+ {
+ return false;
+ }
+ return m_value == ((UInt64)obj).m_value;
+ }
+
+ [System.Runtime.Versioning.NonVersionable]
+ public bool Equals(UInt64 obj)
+ {
+ return m_value == obj;
+ }
+
+ // The value of the lower 32 bits XORed with the uppper 32 bits.
+ public override int GetHashCode()
+ {
+ return ((int)m_value) ^ (int)(m_value >> 32);
+ }
+
+ public override String ToString()
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt64(m_value, null, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt64(m_value, null, NumberFormatInfo.GetInstance(provider));
+ }
+
+ public String ToString(String format)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt64(m_value, format, NumberFormatInfo.CurrentInfo);
+ }
+
+ public String ToString(String format, IFormatProvider provider)
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return Number.FormatUInt64(m_value, format, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static ulong Parse(String s)
+ {
+ return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static ulong Parse(String s, NumberStyles style)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseUInt64(s, style, NumberFormatInfo.CurrentInfo);
+ }
+
+ [CLSCompliant(false)]
+ public static ulong Parse(string s, IFormatProvider provider)
+ {
+ return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static ulong Parse(String s, NumberStyles style, IFormatProvider provider)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.ParseUInt64(s, style, NumberFormatInfo.GetInstance(provider));
+ }
+
+ [CLSCompliant(false)]
+ public static Boolean TryParse(String s, out UInt64 result)
+ {
+ return Number.TryParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
+ public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt64 result)
+ {
+ NumberFormatInfo.ValidateParseStyleInteger(style);
+ return Number.TryParseUInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
+ }
+
+ //
+ // IConvertible implementation
+ //
+
+ public TypeCode GetTypeCode()
+ {
+ return TypeCode.UInt64;
+ }
+
+ bool IConvertible.ToBoolean(IFormatProvider provider)
+ {
+ return Convert.ToBoolean(m_value);
+ }
+
+ char IConvertible.ToChar(IFormatProvider provider)
+ {
+ return Convert.ToChar(m_value);
+ }
+
+ sbyte IConvertible.ToSByte(IFormatProvider provider)
+ {
+ return Convert.ToSByte(m_value);
+ }
+
+ byte IConvertible.ToByte(IFormatProvider provider)
+ {
+ return Convert.ToByte(m_value);
+ }
+
+ short IConvertible.ToInt16(IFormatProvider provider)
+ {
+ return Convert.ToInt16(m_value);
+ }
+
+ ushort IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ return Convert.ToUInt16(m_value);
+ }
+
+ int IConvertible.ToInt32(IFormatProvider provider)
+ {
+ return Convert.ToInt32(m_value);
+ }
+
+ uint IConvertible.ToUInt32(IFormatProvider provider)
+ {
+ return Convert.ToUInt32(m_value);
+ }
+
+ long IConvertible.ToInt64(IFormatProvider provider)
+ {
+ return Convert.ToInt64(m_value);
+ }
+
+ ulong IConvertible.ToUInt64(IFormatProvider provider)
+ {
+ return m_value;
+ }
+
+ float IConvertible.ToSingle(IFormatProvider provider)
+ {
+ return Convert.ToSingle(m_value);
+ }
+
+ double IConvertible.ToDouble(IFormatProvider provider)
+ {
+ return Convert.ToDouble(m_value);
+ }
+
+ Decimal IConvertible.ToDecimal(IFormatProvider provider)
+ {
+ return Convert.ToDecimal(m_value);
+ }
+
+ DateTime IConvertible.ToDateTime(IFormatProvider provider)
+ {
+ throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt64", "DateTime"));
+ }
+
+ Object IConvertible.ToType(Type type, IFormatProvider provider)
+ {
+ return Convert.DefaultToType((IConvertible)this, type, provider);
+ }
+ }
+}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: The boolean class serves as a wrapper for the primitive
-** type boolean.
-**
-**
-===========================================================*/
-
-using System;
-using System.Globalization;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // The Boolean class provides the
- // object representation of the boolean primitive type.
- [Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Boolean : IComparable, IConvertible, IComparable<Boolean>, IEquatable<Boolean>
- {
- //
- // Member Variables
- //
- private bool m_value; // Do not rename (binary serialization)
-
- // The true value.
- //
- internal const int True = 1;
-
- // The false value.
- //
- internal const int False = 0;
-
-
- //
- // Internal Constants are real consts for performance.
- //
-
- // The internal string representation of true.
- //
- internal const String TrueLiteral = "True";
-
- // The internal string representation of false.
- //
- internal const String FalseLiteral = "False";
-
-
- //
- // Public Constants
- //
-
- // The public string representation of true.
- //
- public static readonly String TrueString = TrueLiteral;
-
- // The public string representation of false.
- //
- public static readonly String FalseString = FalseLiteral;
-
- //
- // Overriden Instance Methods
- //
- /*=================================GetHashCode==================================
- **Args: None
- **Returns: 1 or 0 depending on whether this instance represents true or false.
- **Exceptions: None
- **Overriden From: Value
- ==============================================================================*/
- // Provides a hash code for this instance.
- public override int GetHashCode()
- {
- return (m_value) ? True : False;
- }
-
- /*===================================ToString===================================
- **Args: None
- **Returns: "True" or "False" depending on the state of the boolean.
- **Exceptions: None.
- ==============================================================================*/
- // Converts the boolean value of this instance to a String.
- public override String ToString()
- {
- if (false == m_value)
- {
- return FalseLiteral;
- }
- return TrueLiteral;
- }
-
- public String ToString(IFormatProvider provider)
- {
- if (false == m_value)
- {
- return FalseLiteral;
- }
- return TrueLiteral;
- }
-
- // Determines whether two Boolean objects are equal.
- public override bool Equals(Object obj)
- {
- //If it's not a boolean, we're definitely not equal
- if (!(obj is Boolean))
- {
- return false;
- }
-
- return (m_value == ((Boolean)obj).m_value);
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(Boolean obj)
- {
- return m_value == obj;
- }
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship. For booleans, false sorts before true.
- // null is considered to be less than any instance.
- // If object is not of type boolean, this method throws an ArgumentException.
- //
- // Returns a value less than zero if this object
- //
- public int CompareTo(Object obj)
- {
- if (obj == null)
- {
- return 1;
- }
- if (!(obj is Boolean))
- {
- throw new ArgumentException(SR.Arg_MustBeBoolean);
- }
-
- if (m_value == ((Boolean)obj).m_value)
- {
- return 0;
- }
- else if (m_value == false)
- {
- return -1;
- }
- return 1;
- }
-
- public int CompareTo(Boolean value)
- {
- if (m_value == value)
- {
- return 0;
- }
- else if (m_value == false)
- {
- return -1;
- }
- return 1;
- }
-
- //
- // Static Methods
- //
-
- // Determines whether a String represents true or false.
- //
- public static Boolean Parse(String value)
- {
- if (value == null) throw new ArgumentNullException(nameof(value));
- Contract.EndContractBlock();
- Boolean result = false;
- if (!TryParse(value, out result))
- {
- throw new FormatException(SR.Format_BadBoolean);
- }
- else
- {
- return result;
- }
- }
-
- // Determines whether a String represents true or false.
- //
- public static Boolean TryParse(String value, out Boolean result)
- {
- result = false;
- if (value == null)
- {
- return false;
- }
- // For perf reasons, let's first see if they're equal, then do the
- // trim to get rid of white space, and check again.
- if (TrueLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
- {
- result = true;
- return true;
- }
- if (FalseLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
- {
- result = false;
- return true;
- }
-
- // Special case: Trim whitespace as well as null characters.
- value = TrimWhiteSpaceAndNull(value);
-
- if (TrueLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
- {
- result = true;
- return true;
- }
-
- if (FalseLiteral.Equals(value, StringComparison.OrdinalIgnoreCase))
- {
- result = false;
- return true;
- }
-
- return false;
- }
-
- private static String TrimWhiteSpaceAndNull(String value)
- {
- int start = 0;
- int end = value.Length - 1;
- char nullChar = (char)0x0000;
-
- while (start < value.Length)
- {
- if (!Char.IsWhiteSpace(value[start]) && value[start] != nullChar)
- {
- break;
- }
- start++;
- }
-
- while (end >= start)
- {
- if (!Char.IsWhiteSpace(value[end]) && value[end] != nullChar)
- {
- break;
- }
- end--;
- }
-
- return value.Substring(start, end - start + 1);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Boolean;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return m_value;
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "Char"));
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Boolean", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: This class will encapsulate a byte and provide an
-** Object representation of it.
-**
-**
-===========================================================*/
-
-
-using System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // The Byte class extends the Value class and
- // provides object representation of the byte primitive type.
- //
- [Serializable]
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Byte : IComparable, IFormattable, IConvertible
- , IComparable<Byte>, IEquatable<Byte>
- {
- private byte m_value; // Do not rename (binary serialization)
-
- // The maximum value that a Byte may represent: 255.
- public const byte MaxValue = (byte)0xFF;
-
- // The minimum value that a Byte may represent: 0.
- public const byte MinValue = 0;
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type byte, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (!(value is Byte))
- {
- throw new ArgumentException(SR.Arg_MustBeByte);
- }
-
- return m_value - (((Byte)value).m_value);
- }
-
- public int CompareTo(Byte value)
- {
- return m_value - value;
- }
-
- // Determines whether two Byte objects are equal.
- public override bool Equals(Object obj)
- {
- if (!(obj is Byte))
- {
- return false;
- }
- return m_value == ((Byte)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(Byte obj)
- {
- return m_value == obj;
- }
-
- // Gets a hash code for this instance.
- public override int GetHashCode()
- {
- return m_value;
- }
-
- [Pure]
- public static byte Parse(String s)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public static byte Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public static byte Parse(String s, IFormatProvider provider)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
-
- // Parses an unsigned byte from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- [Pure]
- public static byte Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static byte Parse(String s, NumberStyles style, NumberFormatInfo info)
- {
- int i = 0;
- try
- {
- i = Number.ParseInt32(s, style, info);
- }
- catch (OverflowException e)
- {
- throw new OverflowException(SR.Overflow_Byte, e);
- }
-
- if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_Byte);
- return (byte)i;
- }
-
- public static bool TryParse(String s, out Byte result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Byte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out Byte result)
- {
- result = 0;
- int i;
- if (!Number.TryParseInt32(s, style, info, out i))
- {
- return false;
- }
- if (i < MinValue || i > MaxValue)
- {
- return false;
- }
- result = (byte)i;
- return true;
- }
-
- [Pure]
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- [Pure]
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- //
- // IConvertible implementation
- //
- [Pure]
- public TypeCode GetTypeCode()
- {
- return TypeCode.Byte;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return m_value;
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Byte", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: This class will encapsulate a short and provide an
-** Object representation of it.
-**
-**
-===========================================================*/
-
-
-using System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Int16 : IComparable, IFormattable, IConvertible
- , IComparable<Int16>, IEquatable<Int16>
- {
- private short m_value; // Do not rename (binary serialization)
-
- public const short MaxValue = (short)0x7FFF;
- public const short MinValue = unchecked((short)0x8000);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Int16, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
-
- if (value is Int16)
- {
- return m_value - ((Int16)value).m_value;
- }
-
- throw new ArgumentException(SR.Arg_MustBeInt16);
- }
-
- public int CompareTo(Int16 value)
- {
- return m_value - value;
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is Int16))
- {
- return false;
- }
- return m_value == ((Int16)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(Int16 obj)
- {
- return m_value == obj;
- }
-
- // Returns a HashCode for the Int16
- public override int GetHashCode()
- {
- return ((int)((ushort)m_value) | (((int)m_value) << 16));
- }
-
-
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return ToString(format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return ToString(format, NumberFormatInfo.GetInstance(provider));
- }
-
- private String ToString(String format, NumberFormatInfo info)
- {
- Contract.Ensures(Contract.Result<String>() != null);
-
- if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x0000FFFF);
- return Number.FormatUInt32(temp, format, info);
- }
- return Number.FormatInt32(m_value, format, info);
- }
-
- public static short Parse(String s)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static short Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static short Parse(String s, IFormatProvider provider)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- public static short Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static short Parse(String s, NumberStyles style, NumberFormatInfo info)
- {
- int i = 0;
- try
- {
- i = Number.ParseInt32(s, style, info);
- }
- catch (OverflowException e)
- {
- throw new OverflowException(SR.Overflow_Int16, e);
- }
-
- // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
- // for negative numbers
- if ((style & NumberStyles.AllowHexSpecifier) != 0)
- { // We are parsing a hexadecimal number
- if ((i < 0) || (i > UInt16.MaxValue))
- {
- throw new OverflowException(SR.Overflow_Int16);
- }
- return (short)i;
- }
-
- if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_Int16);
- return (short)i;
- }
-
- public static bool TryParse(String s, out Int16 result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int16 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out Int16 result)
- {
- result = 0;
- int i;
- if (!Number.TryParseInt32(s, style, info, out i))
- {
- return false;
- }
-
- // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
- // for negative numbers
- if ((style & NumberStyles.AllowHexSpecifier) != 0)
- { // We are parsing a hexadecimal number
- if ((i < 0) || i > UInt16.MaxValue)
- {
- return false;
- }
- result = (Int16)i;
- return true;
- }
-
- if (i < MinValue || i > MaxValue)
- {
- return false;
- }
- result = (Int16)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int16;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return m_value;
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int16", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: A representation of a 32 bit 2's complement
-** integer.
-**
-**
-===========================================================*/
-
-using System;
-using System.Globalization;
-using System.Runtime;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Int32 : IComparable, IFormattable, IConvertible
- , IComparable<Int32>, IEquatable<Int32>
- {
- private int m_value; // Do not rename (binary serialization)
-
- public const int MaxValue = 0x7fffffff;
- public const int MinValue = unchecked((int)0x80000000);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Int32, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is Int32)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- int i = (int)value;
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
- throw new ArgumentException(SR.Arg_MustBeInt32);
- }
-
- public int CompareTo(int value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is Int32))
- {
- return false;
- }
- return m_value == ((Int32)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(Int32 obj)
- {
- return m_value == obj;
- }
-
- // The absolute value of the int contained.
- public override int GetHashCode()
- {
- return m_value;
- }
-
- [Pure]
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- [Pure]
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- [Pure]
- public static int Parse(String s)
- {
- return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [Pure]
- public static int Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- // Parses an integer from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- [Pure]
- public static int Parse(String s, IFormatProvider provider)
- {
- return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses an integer from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- [Pure]
- public static int Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses an integer from a String. Returns false rather
- // than throwing exceptin if input is invalid
- //
- [Pure]
- public static bool TryParse(String s, out Int32 result)
- {
- return Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- // Parses an integer from a String in the given style. Returns false rather
- // than throwing exceptin if input is invalid
- //
- [Pure]
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- //
- // IConvertible implementation
- //
-
- [Pure]
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int32;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return m_value;
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int32", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: This class will encapsulate a long and provide an
-** Object representation of it.
-**
-**
-===========================================================*/
-
-using System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- [Serializable]
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct Int64 : IComparable, IFormattable, IConvertible
- , IComparable<Int64>, IEquatable<Int64>
- {
- private long m_value; // Do not rename (binary serialization)
-
- public const long MaxValue = 0x7fffffffffffffffL;
- public const long MinValue = unchecked((long)0x8000000000000000L);
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type Int64, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is Int64)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- long i = (long)value;
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
- throw new ArgumentException(SR.Arg_MustBeInt64);
- }
-
- public int CompareTo(Int64 value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is Int64))
- {
- return false;
- }
- return m_value == ((Int64)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(Int64 obj)
- {
- return m_value == obj;
- }
-
- // The value of the lower 32 bits XORed with the uppper 32 bits.
- public override int GetHashCode()
- {
- return (unchecked((int)((long)m_value)) ^ (int)(m_value >> 32));
- }
-
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt64(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt64(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt64(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt64(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- public static long Parse(String s)
- {
- return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- public static long Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt64(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- public static long Parse(String s, IFormatProvider provider)
- {
- return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
-
- // Parses a long from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- public static long Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- public static Boolean TryParse(String s, out Int64 result)
- {
- return Number.TryParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Int64 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.Int64;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return m_value;
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "Int64", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose:
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // A place holder class for signed bytes.
- [Serializable]
- [CLSCompliant(false), System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SByte : IComparable, IFormattable, IConvertible
- , IComparable<SByte>, IEquatable<SByte>
- {
- private sbyte m_value; // Do not rename (binary serialization)
-
- // The maximum value that a Byte may represent: 127.
- public const sbyte MaxValue = (sbyte)0x7F;
-
- // The minimum value that a Byte may represent: -128.
- public const sbyte MinValue = unchecked((sbyte)0x80);
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type SByte, this method throws an ArgumentException.
- //
- public int CompareTo(Object obj)
- {
- if (obj == null)
- {
- return 1;
- }
- if (!(obj is SByte))
- {
- throw new ArgumentException(SR.Arg_MustBeSByte);
- }
- return m_value - ((SByte)obj).m_value;
- }
-
- public int CompareTo(SByte value)
- {
- return m_value - value;
- }
-
- // Determines whether two Byte objects are equal.
- public override bool Equals(Object obj)
- {
- if (!(obj is SByte))
- {
- return false;
- }
- return m_value == ((SByte)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(SByte obj)
- {
- return m_value == obj;
- }
-
- // Gets a hash code for this instance.
- public override int GetHashCode()
- {
- return ((int)m_value ^ (int)m_value << 8);
- }
-
-
- // Provides a string representation of a byte.
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return ToString(format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return ToString(format, NumberFormatInfo.GetInstance(provider));
- }
-
- private String ToString(String format, NumberFormatInfo info)
- {
- Contract.Ensures(Contract.Result<String>() != null);
-
- if (m_value < 0 && format != null && format.Length > 0 && (format[0] == 'X' || format[0] == 'x'))
- {
- uint temp = (uint)(m_value & 0x000000FF);
- return Number.FormatUInt32(temp, format, info);
- }
- return Number.FormatInt32(m_value, format, info);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(String s)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static sbyte Parse(String s, IFormatProvider provider)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- // Parses a signed byte from a String in the given style. If
- // a NumberFormatInfo isn't specified, the current culture's
- // NumberFormatInfo is assumed.
- //
- [CLSCompliant(false)]
- public static sbyte Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static sbyte Parse(String s, NumberStyles style, NumberFormatInfo info)
- {
- int i = 0;
- try
- {
- i = Number.ParseInt32(s, style, info);
- }
- catch (OverflowException e)
- {
- throw new OverflowException(SR.Overflow_SByte, e);
- }
-
- if ((style & NumberStyles.AllowHexSpecifier) != 0)
- { // We are parsing a hexadecimal number
- if ((i < 0) || i > Byte.MaxValue)
- {
- throw new OverflowException(SR.Overflow_SByte);
- }
- return (sbyte)i;
- }
-
- if (i < MinValue || i > MaxValue) throw new OverflowException(SR.Overflow_SByte);
- return (sbyte)i;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, out SByte result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out SByte result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out SByte result)
- {
- result = 0;
- int i;
- if (!Number.TryParseInt32(s, style, info, out i))
- {
- return false;
- }
-
- if ((style & NumberStyles.AllowHexSpecifier) != 0)
- { // We are parsing a hexadecimal number
- if ((i < 0) || i > Byte.MaxValue)
- {
- return false;
- }
- result = (sbyte)i;
- return true;
- }
-
- if (i < MinValue || i > MaxValue)
- {
- return false;
- }
- result = (sbyte)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.SByte;
- }
-
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return m_value;
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return m_value;
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "SByte", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-** Purpose: This class will encapsulate a short and provide an
-** Object representation of it.
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // Wrapper for unsigned 16 bit integers.
- [Serializable]
- [CLSCompliant(false), System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct UInt16 : IComparable, IFormattable, IConvertible
- , IComparable<UInt16>, IEquatable<UInt16>
- {
- private ushort m_value; // Do not rename (binary serialization)
-
- public const ushort MaxValue = (ushort)0xFFFF;
- public const ushort MinValue = 0;
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt16, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is UInt16)
- {
- return ((int)m_value - (int)(((UInt16)value).m_value));
- }
- throw new ArgumentException(SR.Arg_MustBeUInt16);
- }
-
- public int CompareTo(UInt16 value)
- {
- return ((int)m_value - (int)value);
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is UInt16))
- {
- return false;
- }
- return m_value == ((UInt16)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(UInt16 obj)
- {
- return m_value == obj;
- }
-
- // Returns a HashCode for the UInt16
- public override int GetHashCode()
- {
- return (int)m_value;
- }
-
- // Converts the current value to a String in base-10 with no extra padding.
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(String s)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.CurrentInfo);
- }
-
-
- [CLSCompliant(false)]
- public static ushort Parse(String s, IFormatProvider provider)
- {
- return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ushort Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Parse(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- private static ushort Parse(String s, NumberStyles style, NumberFormatInfo info)
- {
- uint i = 0;
- try
- {
- i = Number.ParseUInt32(s, style, info);
- }
- catch (OverflowException e)
- {
- throw new OverflowException(SR.Overflow_UInt16, e);
- }
-
- if (i > MaxValue) throw new OverflowException(SR.Overflow_UInt16);
- return (ushort)i;
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, out UInt16 result)
- {
- return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt16 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out UInt16 result)
- {
- result = 0;
- UInt32 i;
- if (!Number.TryParseUInt32(s, style, info, out i))
- {
- return false;
- }
- if (i > MaxValue)
- {
- return false;
- }
- result = (UInt16)i;
- return true;
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt16;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return m_value;
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt16", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: This class will encapsulate an uint and
-** provide an Object representation of it.
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System;
-using System.Runtime;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // * Wrapper for unsigned 32 bit integers.
- [Serializable]
- [CLSCompliant(false), System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct UInt32 : IComparable, IFormattable, IConvertible
- , IComparable<UInt32>, IEquatable<UInt32>
- {
- private uint m_value; // Do not rename (binary serialization)
-
- public const uint MaxValue = (uint)0xffffffff;
- public const uint MinValue = 0U;
-
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt32, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is UInt32)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- uint i = (uint)value;
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
- throw new ArgumentException(SR.Arg_MustBeUInt32);
- }
-
- public int CompareTo(UInt32 value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is UInt32))
- {
- return false;
- }
- return m_value == ((UInt32)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(UInt32 obj)
- {
- return m_value == obj;
- }
-
- // The absolute value of the int contained.
- public override int GetHashCode()
- {
- return ((int)m_value);
- }
-
- // The base 10 representation of the number with no extra padding.
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt32(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static uint Parse(String s)
- {
- return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static uint Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt32(s, style, NumberFormatInfo.CurrentInfo);
- }
-
-
- [CLSCompliant(false)]
- public static uint Parse(String s, IFormatProvider provider)
- {
- return Number.ParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static uint Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt32(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, out UInt32 result)
- {
- return Number.TryParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt32 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseUInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt32;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return m_value;
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return Convert.ToUInt64(m_value);
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt32", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-** Purpose: This class will encapsulate an unsigned long and
-** provide an Object representation of it.
-**
-**
-===========================================================*/
-
-using System.Globalization;
-using System;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
-
-namespace System
-{
- // Wrapper for unsigned 64 bit integers.
- [Serializable]
- [CLSCompliant(false), System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct UInt64 : IComparable, IFormattable, IConvertible
- , IComparable<UInt64>, IEquatable<UInt64>
- {
- private ulong m_value; // Do not rename (binary serialization)
-
- public const ulong MaxValue = (ulong)0xffffffffffffffffL;
- public const ulong MinValue = 0x0;
-
- // Compares this object to another object, returning an integer that
- // indicates the relationship.
- // Returns a value less than zero if this object
- // null is considered to be less than any instance.
- // If object is not of type UInt64, this method throws an ArgumentException.
- //
- public int CompareTo(Object value)
- {
- if (value == null)
- {
- return 1;
- }
- if (value is UInt64)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- ulong i = (ulong)value;
- if (m_value < i) return -1;
- if (m_value > i) return 1;
- return 0;
- }
- throw new ArgumentException(SR.Arg_MustBeUInt64);
- }
-
- public int CompareTo(UInt64 value)
- {
- // Need to use compare because subtraction will wrap
- // to positive for very large neg numbers, etc.
- if (m_value < value) return -1;
- if (m_value > value) return 1;
- return 0;
- }
-
- public override bool Equals(Object obj)
- {
- if (!(obj is UInt64))
- {
- return false;
- }
- return m_value == ((UInt64)obj).m_value;
- }
-
- [System.Runtime.Versioning.NonVersionable]
- public bool Equals(UInt64 obj)
- {
- return m_value == obj;
- }
-
- // The value of the lower 32 bits XORed with the uppper 32 bits.
- public override int GetHashCode()
- {
- return ((int)m_value) ^ (int)(m_value >> 32);
- }
-
- public override String ToString()
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt64(m_value, null, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt64(m_value, null, NumberFormatInfo.GetInstance(provider));
- }
-
- public String ToString(String format)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt64(m_value, format, NumberFormatInfo.CurrentInfo);
- }
-
- public String ToString(String format, IFormatProvider provider)
- {
- Contract.Ensures(Contract.Result<String>() != null);
- return Number.FormatUInt64(m_value, format, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(String s)
- {
- return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(String s, NumberStyles style)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt64(s, style, NumberFormatInfo.CurrentInfo);
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(string s, IFormatProvider provider)
- {
- return Number.ParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static ulong Parse(String s, NumberStyles style, IFormatProvider provider)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.ParseUInt64(s, style, NumberFormatInfo.GetInstance(provider));
- }
-
- [CLSCompliant(false)]
- public static Boolean TryParse(String s, out UInt64 result)
- {
- return Number.TryParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
- }
-
- [CLSCompliant(false)]
- public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt64 result)
- {
- NumberFormatInfo.ValidateParseStyleInteger(style);
- return Number.TryParseUInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
- }
-
- //
- // IConvertible implementation
- //
-
- public TypeCode GetTypeCode()
- {
- return TypeCode.UInt64;
- }
-
- bool IConvertible.ToBoolean(IFormatProvider provider)
- {
- return Convert.ToBoolean(m_value);
- }
-
- char IConvertible.ToChar(IFormatProvider provider)
- {
- return Convert.ToChar(m_value);
- }
-
- sbyte IConvertible.ToSByte(IFormatProvider provider)
- {
- return Convert.ToSByte(m_value);
- }
-
- byte IConvertible.ToByte(IFormatProvider provider)
- {
- return Convert.ToByte(m_value);
- }
-
- short IConvertible.ToInt16(IFormatProvider provider)
- {
- return Convert.ToInt16(m_value);
- }
-
- ushort IConvertible.ToUInt16(IFormatProvider provider)
- {
- return Convert.ToUInt16(m_value);
- }
-
- int IConvertible.ToInt32(IFormatProvider provider)
- {
- return Convert.ToInt32(m_value);
- }
-
- uint IConvertible.ToUInt32(IFormatProvider provider)
- {
- return Convert.ToUInt32(m_value);
- }
-
- long IConvertible.ToInt64(IFormatProvider provider)
- {
- return Convert.ToInt64(m_value);
- }
-
- ulong IConvertible.ToUInt64(IFormatProvider provider)
- {
- return m_value;
- }
-
- float IConvertible.ToSingle(IFormatProvider provider)
- {
- return Convert.ToSingle(m_value);
- }
-
- double IConvertible.ToDouble(IFormatProvider provider)
- {
- return Convert.ToDouble(m_value);
- }
-
- Decimal IConvertible.ToDecimal(IFormatProvider provider)
- {
- return Convert.ToDecimal(m_value);
- }
-
- DateTime IConvertible.ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "UInt64", "DateTime"));
- }
-
- Object IConvertible.ToType(Type type, IFormatProvider provider)
- {
- return Convert.DefaultToType((IConvertible)this, type, provider);
- }
- }
-}