.NET Framework - 数据类型转换 - System.Convert 类

创建时间:
2017-04-21 04:42
最近更新:
2018-06-17 00:02

Resource - MSDN

  1. System.Convert 类 - Converts a base data type to another base data type (将一个基本数据类型转换为另一个基本数据类型).
  2. System.Convert.ToString 方法

Tony Note

该类为 static 类,该类的全部成员均为 public static。该类的成员除了 public static readonly object DBNull 字段,其它全部是方法。

Source Code of System.Convert from JetBrains dotPeek 1.0 at 2015-05-16

// Type: System.Convert
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Globalization;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;

namespace System
{
  [__DynamicallyInvokable]
  public static class Convert
  {
    internal static readonly RuntimeType[] ConvertTypes = new RuntimeType[19]
    {
      (RuntimeType) typeof (Empty),
      (RuntimeType) typeof (object),
      (RuntimeType) typeof (DBNull),
      (RuntimeType) typeof (bool),
      (RuntimeType) typeof (char),
      (RuntimeType) typeof (sbyte),
      (RuntimeType) typeof (byte),
      (RuntimeType) typeof (short),
      (RuntimeType) typeof (ushort),
      (RuntimeType) typeof (int),
      (RuntimeType) typeof (uint),
      (RuntimeType) typeof (long),
      (RuntimeType) typeof (ulong),
      (RuntimeType) typeof (float),
      (RuntimeType) typeof (double),
      (RuntimeType) typeof (Decimal),
      (RuntimeType) typeof (DateTime),
      (RuntimeType) typeof (object),
      (RuntimeType) typeof (string)
    };
    private static readonly RuntimeType EnumType = (RuntimeType) typeof (Enum);
    internal static readonly char[] base64Table = new char[65]
    {
      'A',
      'B',
      'C',
      'D',
      'E',
      'F',
      'G',
      'H',
      'I',
      'J',
      'K',
      'L',
      'M',
      'N',
      'O',
      'P',
      'Q',
      'R',
      'S',
      'T',
      'U',
      'V',
      'W',
      'X',
      'Y',
      'Z',
      'a',
      'b',
      'c',
      'd',
      'e',
      'f',
      'g',
      'h',
      'i',
      'j',
      'k',
      'l',
      'm',
      'n',
      'o',
      'p',
      'q',
      'r',
      's',
      't',
      'u',
      'v',
      'w',
      'x',
      'y',
      'z',
      '0',
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      '9',
      '+',
      '/',
      '='
    };
    public static readonly object DBNull = (object) DBNull.Value;
    private const int base64LineBreakPosition = 76;

    static Convert()
    {
    }

    public static TypeCode GetTypeCode(object value)
    {
      if (value == null)
        return TypeCode.Empty;
      IConvertible convertible = value as IConvertible;
      if (convertible != null)
        return convertible.GetTypeCode();
      else
        return TypeCode.Object;
    }

    public static bool IsDBNull(object value)
    {
      if (value == DBNull.Value)
        return true;
      IConvertible convertible = value as IConvertible;
      if (convertible == null)
        return false;
      else
        return convertible.GetTypeCode() == TypeCode.DBNull;
    }

    public static object ChangeType(object value, TypeCode typeCode)
    {
      return Convert.ChangeType(value, typeCode, (IFormatProvider) Thread.CurrentThread.CurrentCulture);
    }

    public static object ChangeType(object value, TypeCode typeCode, IFormatProvider provider)
    {
      if (value == null && (typeCode == TypeCode.Empty || typeCode == TypeCode.String || typeCode == TypeCode.Object))
        return (object) null;
      IConvertible convertible = value as IConvertible;
      if (convertible == null)
        throw new InvalidCastException(Environment.GetResourceString("InvalidCast_IConvertible"));
      switch (typeCode)
      {
        case TypeCode.Empty:
          throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty"));
        case TypeCode.Object:
          return value;
        case TypeCode.DBNull:
          throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));
        case TypeCode.Boolean:
          return (object) (bool) (convertible.ToBoolean(provider) ? 1 : 0);
        case TypeCode.Char:
          return (object) convertible.ToChar(provider);
        case TypeCode.SByte:
          return (object) convertible.ToSByte(provider);
        case TypeCode.Byte:
          return (object) convertible.ToByte(provider);
        case TypeCode.Int16:
          return (object) convertible.ToInt16(provider);
        case TypeCode.UInt16:
          return (object) convertible.ToUInt16(provider);
        case TypeCode.Int32:
          return (object) convertible.ToInt32(provider);
        case TypeCode.UInt32:
          return (object) convertible.ToUInt32(provider);
        case TypeCode.Int64:
          return (object) convertible.ToInt64(provider);
        case TypeCode.UInt64:
          return (object) convertible.ToUInt64(provider);
        case TypeCode.Single:
          return (object) convertible.ToSingle(provider);
        case TypeCode.Double:
          return (object) convertible.ToDouble(provider);
        case TypeCode.Decimal:
          return (object) convertible.ToDecimal(provider);
        case TypeCode.DateTime:
          return (object) convertible.ToDateTime(provider);
        case TypeCode.String:
          return (object) convertible.ToString(provider);
        default:
          throw new ArgumentException(Environment.GetResourceString("Arg_UnknownTypeCode"));
      }
    }

    internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
    {
      if (targetType == (Type) null)
        throw new ArgumentNullException("targetType");
      RuntimeType runtimeType = targetType as RuntimeType;
      if (runtimeType != (RuntimeType) null)
      {
        if (value.GetType() == targetType)
          return (object) value;
        if (runtimeType == Convert.ConvertTypes[3])
          return (object) (bool) (value.ToBoolean(provider) ? 1 : 0);
        if (runtimeType == Convert.ConvertTypes[4])
          return (object) value.ToChar(provider);
        if (runtimeType == Convert.ConvertTypes[5])
          return (object) value.ToSByte(provider);
        if (runtimeType == Convert.ConvertTypes[6])
          return (object) value.ToByte(provider);
        if (runtimeType == Convert.ConvertTypes[7])
          return (object) value.ToInt16(provider);
        if (runtimeType == Convert.ConvertTypes[8])
          return (object) value.ToUInt16(provider);
        if (runtimeType == Convert.ConvertTypes[9])
          return (object) value.ToInt32(provider);
        if (runtimeType == Convert.ConvertTypes[10])
          return (object) value.ToUInt32(provider);
        if (runtimeType == Convert.ConvertTypes[11])
          return (object) value.ToInt64(provider);
        if (runtimeType == Convert.ConvertTypes[12])
          return (object) value.ToUInt64(provider);
        if (runtimeType == Convert.ConvertTypes[13])
          return (object) value.ToSingle(provider);
        if (runtimeType == Convert.ConvertTypes[14])
          return (object) value.ToDouble(provider);
        if (runtimeType == Convert.ConvertTypes[15])
          return (object) value.ToDecimal(provider);
        if (runtimeType == Convert.ConvertTypes[16])
          return (object) value.ToDateTime(provider);
        if (runtimeType == Convert.ConvertTypes[18])
          return (object) value.ToString(provider);
        if (runtimeType == Convert.ConvertTypes[1])
          return (object) value;
        if (runtimeType == Convert.EnumType)
          return (object) (Enum) value;
        if (runtimeType == Convert.ConvertTypes[2])
          throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));
        if (runtimeType == Convert.ConvertTypes[0])
          throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty"));
      }
      throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", (object) value.GetType().FullName, (object) targetType.FullName));
    }

    [__DynamicallyInvokable]
    public static object ChangeType(object value, Type conversionType)
    {
      return Convert.ChangeType(value, conversionType, (IFormatProvider) Thread.CurrentThread.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static object ChangeType(object value, Type conversionType, IFormatProvider provider)
    {
      if (conversionType == (Type) null)
        throw new ArgumentNullException("conversionType");
      if (value == null)
      {
        if (conversionType.IsValueType)
          throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCastNullToValueType"));
        else
          return (object) null;
      }
      else
      {
        IConvertible convertible = value as IConvertible;
        if (convertible == null)
        {
          if (value.GetType() == conversionType)
            return value;
          else
            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_IConvertible"));
        }
        else
        {
          RuntimeType runtimeType = conversionType as RuntimeType;
          if (runtimeType == Convert.ConvertTypes[3])
            return (object) (bool) (convertible.ToBoolean(provider) ? 1 : 0);
          if (runtimeType == Convert.ConvertTypes[4])
            return (object) convertible.ToChar(provider);
          if (runtimeType == Convert.ConvertTypes[5])
            return (object) convertible.ToSByte(provider);
          if (runtimeType == Convert.ConvertTypes[6])
            return (object) convertible.ToByte(provider);
          if (runtimeType == Convert.ConvertTypes[7])
            return (object) convertible.ToInt16(provider);
          if (runtimeType == Convert.ConvertTypes[8])
            return (object) convertible.ToUInt16(provider);
          if (runtimeType == Convert.ConvertTypes[9])
            return (object) convertible.ToInt32(provider);
          if (runtimeType == Convert.ConvertTypes[10])
            return (object) convertible.ToUInt32(provider);
          if (runtimeType == Convert.ConvertTypes[11])
            return (object) convertible.ToInt64(provider);
          if (runtimeType == Convert.ConvertTypes[12])
            return (object) convertible.ToUInt64(provider);
          if (runtimeType == Convert.ConvertTypes[13])
            return (object) convertible.ToSingle(provider);
          if (runtimeType == Convert.ConvertTypes[14])
            return (object) convertible.ToDouble(provider);
          if (runtimeType == Convert.ConvertTypes[15])
            return (object) convertible.ToDecimal(provider);
          if (runtimeType == Convert.ConvertTypes[16])
            return (object) convertible.ToDateTime(provider);
          if (runtimeType == Convert.ConvertTypes[18])
            return (object) convertible.ToString(provider);
          if (runtimeType == Convert.ConvertTypes[1])
            return value;
          else
            return convertible.ToType(conversionType, provider);
        }
      }
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToBoolean((IFormatProvider) null);
      else
        return false;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToBoolean(provider);
      else
        return false;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(bool value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static bool ToBoolean(sbyte value)
    {
      return (int) value != 0;
    }

    public static bool ToBoolean(char value)
    {
      return ((IConvertible) value).ToBoolean((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(byte value)
    {
      return (int) value != 0;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(short value)
    {
      return (int) value != 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static bool ToBoolean(ushort value)
    {
      return (int) value != 0;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(int value)
    {
      return value != 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static bool ToBoolean(uint value)
    {
      return (int) value != 0;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(long value)
    {
      return value != 0L;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static bool ToBoolean(ulong value)
    {
      return (long) value != 0L;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(string value)
    {
      if (value == null)
        return false;
      else
        return bool.Parse(value);
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(string value, IFormatProvider provider)
    {
      if (value == null)
        return false;
      else
        return bool.Parse(value);
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(float value)
    {
      return (double) value != 0.0;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(double value)
    {
      return value != 0.0;
    }

    [__DynamicallyInvokable]
    public static bool ToBoolean(Decimal value)
    {
      return value != new Decimal(0);
    }

    public static bool ToBoolean(DateTime value)
    {
      return ((IConvertible) value).ToBoolean((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static char ToChar(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToChar((IFormatProvider) null);
      else
        return char.MinValue;
    }

    [__DynamicallyInvokable]
    public static char ToChar(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToChar(provider);
      else
        return char.MinValue;
    }

    public static char ToChar(bool value)
    {
      return ((IConvertible) (bool) (value ? 1 : 0)).ToChar((IFormatProvider) null);
    }

    public static char ToChar(char value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static char ToChar(sbyte value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [__DynamicallyInvokable]
    public static char ToChar(byte value)
    {
      return (char) value;
    }

    [__DynamicallyInvokable]
    public static char ToChar(short value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static char ToChar(ushort value)
    {
      return (char) value;
    }

    [__DynamicallyInvokable]
    public static char ToChar(int value)
    {
      if (value < 0 || value > (int) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static char ToChar(uint value)
    {
      if (value > (uint) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [__DynamicallyInvokable]
    public static char ToChar(long value)
    {
      if (value < 0L || value > (long) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static char ToChar(ulong value)
    {
      if (value > (ulong) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Char"));
      else
        return (char) value;
    }

    [__DynamicallyInvokable]
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public static char ToChar(string value)
    {
      return Convert.ToChar(value, (IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static char ToChar(string value, IFormatProvider provider)
    {
      if (value == null)
        throw new ArgumentNullException("value");
      if (value.Length != 1)
        throw new FormatException(Environment.GetResourceString("Format_NeedSingleChar"));
      else
        return value[0];
    }

    public static char ToChar(float value)
    {
      return ((IConvertible) value).ToChar((IFormatProvider) null);
    }

    public static char ToChar(double value)
    {
      return ((IConvertible) value).ToChar((IFormatProvider) null);
    }

    public static char ToChar(Decimal value)
    {
      return ((IConvertible) value).ToChar((IFormatProvider) null);
    }

    public static char ToChar(DateTime value)
    {
      return ((IConvertible) value).ToChar((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToSByte((IFormatProvider) null);
      else
        return (sbyte) 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToSByte(provider);
      else
        return (sbyte) 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(bool value)
    {
      return !value ? (sbyte) 0 : (sbyte) 1;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(sbyte value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(char value)
    {
      if ((int) value > (int) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(byte value)
    {
      if ((int) value > (int) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(short value)
    {
      if ((int) value < (int) sbyte.MinValue || (int) value > (int) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(ushort value)
    {
      if ((int) value > (int) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(int value)
    {
      if (value < (int) sbyte.MinValue || value > (int) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(uint value)
    {
      if ((long) value > (long) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(long value)
    {
      if (value < (long) sbyte.MinValue || value > (long) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(ulong value)
    {
      if (value > (ulong) sbyte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
      else
        return (sbyte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(float value)
    {
      return Convert.ToSByte((double) value);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(double value)
    {
      return Convert.ToSByte(Convert.ToInt32(value));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(Decimal value)
    {
      return Decimal.ToSByte(Decimal.Round(value, 0));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(string value)
    {
      if (value == null)
        return (sbyte) 0;
      else
        return sbyte.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(string value, IFormatProvider provider)
    {
      return sbyte.Parse(value, NumberStyles.Integer, provider);
    }

    [CLSCompliant(false)]
    public static sbyte ToSByte(DateTime value)
    {
      return ((IConvertible) value).ToSByte((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static byte ToByte(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToByte((IFormatProvider) null);
      else
        return (byte) 0;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToByte(provider);
      else
        return (byte) 0;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(bool value)
    {
      return !value ? (byte) 0 : (byte) 1;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(byte value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(char value)
    {
      if ((int) value > (int) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static byte ToByte(sbyte value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(short value)
    {
      if ((int) value < 0 || (int) value > (int) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static byte ToByte(ushort value)
    {
      if ((int) value > (int) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(int value)
    {
      if (value < 0 || value > (int) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static byte ToByte(uint value)
    {
      if (value > (uint) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(long value)
    {
      if (value < 0L || value > (long) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static byte ToByte(ulong value)
    {
      if (value > (ulong) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(float value)
    {
      return Convert.ToByte((double) value);
    }

    [__DynamicallyInvokable]
    public static byte ToByte(double value)
    {
      return Convert.ToByte(Convert.ToInt32(value));
    }

    [__DynamicallyInvokable]
    public static byte ToByte(Decimal value)
    {
      return Decimal.ToByte(Decimal.Round(value, 0));
    }

    [__DynamicallyInvokable]
    public static byte ToByte(string value)
    {
      if (value == null)
        return (byte) 0;
      else
        return byte.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static byte ToByte(string value, IFormatProvider provider)
    {
      if (value == null)
        return (byte) 0;
      else
        return byte.Parse(value, NumberStyles.Integer, provider);
    }

    public static byte ToByte(DateTime value)
    {
      return ((IConvertible) value).ToByte((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static short ToInt16(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToInt16((IFormatProvider) null);
      else
        return (short) 0;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToInt16(provider);
      else
        return (short) 0;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(bool value)
    {
      return !value ? (short) 0 : (short) 1;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(char value)
    {
      if ((int) value > (int) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static short ToInt16(sbyte value)
    {
      return (short) value;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(byte value)
    {
      return (short) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static short ToInt16(ushort value)
    {
      if ((int) value > (int) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(int value)
    {
      if (value < (int) short.MinValue || value > (int) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static short ToInt16(uint value)
    {
      if ((long) value > (long) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(short value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(long value)
    {
      if (value < (long) short.MinValue || value > (long) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static short ToInt16(ulong value)
    {
      if (value > (ulong) short.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
      else
        return (short) value;
    }

    [__DynamicallyInvokable]
    public static short ToInt16(float value)
    {
      return Convert.ToInt16((double) value);
    }

    [__DynamicallyInvokable]
    public static short ToInt16(double value)
    {
      return Convert.ToInt16(Convert.ToInt32(value));
    }

    [__DynamicallyInvokable]
    public static short ToInt16(Decimal value)
    {
      return Decimal.ToInt16(Decimal.Round(value, 0));
    }

    [__DynamicallyInvokable]
    public static short ToInt16(string value)
    {
      if (value == null)
        return (short) 0;
      else
        return short.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static short ToInt16(string value, IFormatProvider provider)
    {
      if (value == null)
        return (short) 0;
      else
        return short.Parse(value, NumberStyles.Integer, provider);
    }

    public static short ToInt16(DateTime value)
    {
      return ((IConvertible) value).ToInt16((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt16((IFormatProvider) null);
      else
        return (ushort) 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt16(provider);
      else
        return (ushort) 0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(bool value)
    {
      return !value ? (ushort) 0 : (ushort) 1;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(char value)
    {
      return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(sbyte value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(byte value)
    {
      return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(short value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(int value)
    {
      if (value < 0 || value > (int) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(ushort value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(uint value)
    {
      if (value > (uint) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(long value)
    {
      if (value < 0L || value > (long) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(ulong value)
    {
      if (value > (ulong) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(float value)
    {
      return Convert.ToUInt16((double) value);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(double value)
    {
      return Convert.ToUInt16(Convert.ToInt32(value));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(Decimal value)
    {
      return Decimal.ToUInt16(Decimal.Round(value, 0));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(string value)
    {
      if (value == null)
        return (ushort) 0;
      else
        return ushort.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(string value, IFormatProvider provider)
    {
      if (value == null)
        return (ushort) 0;
      else
        return ushort.Parse(value, NumberStyles.Integer, provider);
    }

    [CLSCompliant(false)]
    public static ushort ToUInt16(DateTime value)
    {
      return ((IConvertible) value).ToUInt16((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static int ToInt32(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToInt32((IFormatProvider) null);
      else
        return 0;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToInt32(provider);
      else
        return 0;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(bool value)
    {
      return !value ? 0 : 1;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(char value)
    {
      return (int) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static int ToInt32(sbyte value)
    {
      return (int) value;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(byte value)
    {
      return (int) value;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(short value)
    {
      return (int) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static int ToInt32(ushort value)
    {
      return (int) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static int ToInt32(uint value)
    {
      if (value > (uint) int.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
      else
        return (int) value;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(int value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(long value)
    {
      if (value < (long) int.MinValue || value > (long) int.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
      else
        return (int) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static int ToInt32(ulong value)
    {
      if (value > (ulong) int.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
      else
        return (int) value;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(float value)
    {
      return Convert.ToInt32((double) value);
    }

    [__DynamicallyInvokable]
    public static int ToInt32(double value)
    {
      if (value >= 0.0)
      {
        if (value < 2147483647.5)
        {
          int num1 = (int) value;
          double num2 = value - (double) num1;
          if (num2 > 0.5 || num2 == 0.5 && (num1 & 1) != 0)
            ++num1;
          return num1;
        }
      }
      else if (value >= -2147483648.5)
      {
        int num1 = (int) value;
        double num2 = value - (double) num1;
        if (num2 < -0.5 || num2 == -0.5 && (num1 & 1) != 0)
          --num1;
        return num1;
      }
      throw new OverflowException(Environment.GetResourceString("Overflow_Int32"));
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static int ToInt32(Decimal value)
    {
      return Decimal.FCallToInt32(value);
    }

    [__DynamicallyInvokable]
    public static int ToInt32(string value)
    {
      if (value == null)
        return 0;
      else
        return int.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static int ToInt32(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0;
      else
        return int.Parse(value, NumberStyles.Integer, provider);
    }

    public static int ToInt32(DateTime value)
    {
      return ((IConvertible) value).ToInt32((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt32((IFormatProvider) null);
      else
        return 0U;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt32(provider);
      else
        return 0U;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(bool value)
    {
      return !value ? 0U : 1U;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(char value)
    {
      return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(sbyte value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      else
        return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(byte value)
    {
      return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(short value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      else
        return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(ushort value)
    {
      return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(int value)
    {
      if (value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      else
        return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(uint value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(long value)
    {
      if (value < 0L || value > (long) uint.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      else
        return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(ulong value)
    {
      if (value > (ulong) uint.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      else
        return (uint) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(float value)
    {
      return Convert.ToUInt32((double) value);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(double value)
    {
      if (value < -0.5 || value >= 4294967295.5)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt32"));
      uint num1 = (uint) value;
      double num2 = value - (double) num1;
      if (num2 > 0.5 || num2 == 0.5 && ((int) num1 & 1) != 0)
        ++num1;
      return num1;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(Decimal value)
    {
      return Decimal.ToUInt32(Decimal.Round(value, 0));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(string value)
    {
      if (value == null)
        return 0U;
      else
        return uint.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0U;
      else
        return uint.Parse(value, NumberStyles.Integer, provider);
    }

    [CLSCompliant(false)]
    public static uint ToUInt32(DateTime value)
    {
      return ((IConvertible) value).ToUInt32((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static long ToInt64(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToInt64((IFormatProvider) null);
      else
        return 0L;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToInt64(provider);
      else
        return 0L;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(bool value)
    {
      return value ? 1L : 0L;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(char value)
    {
      return (long) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static long ToInt64(sbyte value)
    {
      return (long) value;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(byte value)
    {
      return (long) value;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(short value)
    {
      return (long) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static long ToInt64(ushort value)
    {
      return (long) value;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(int value)
    {
      return (long) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static long ToInt64(uint value)
    {
      return (long) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static long ToInt64(ulong value)
    {
      if (value > 9223372036854775807UL)
        throw new OverflowException(Environment.GetResourceString("Overflow_Int64"));
      else
        return (long) value;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(long value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static long ToInt64(float value)
    {
      return Convert.ToInt64((double) value);
    }

    [__DynamicallyInvokable]
    public static long ToInt64(double value)
    {
      return checked ((long) Math.Round(value));
    }

    [__DynamicallyInvokable]
    public static long ToInt64(Decimal value)
    {
      return Decimal.ToInt64(Decimal.Round(value, 0));
    }

    [__DynamicallyInvokable]
    public static long ToInt64(string value)
    {
      if (value == null)
        return 0L;
      else
        return long.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static long ToInt64(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0L;
      else
        return long.Parse(value, NumberStyles.Integer, provider);
    }

    public static long ToInt64(DateTime value)
    {
      return ((IConvertible) value).ToInt64((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt64((IFormatProvider) null);
      else
        return 0UL;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToUInt64(provider);
      else
        return 0UL;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(bool value)
    {
      return !value ? 0UL : 1UL;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(char value)
    {
      return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(sbyte value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt64"));
      else
        return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(byte value)
    {
      return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(short value)
    {
      if ((int) value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt64"));
      else
        return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(ushort value)
    {
      return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(int value)
    {
      if (value < 0)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt64"));
      else
        return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(uint value)
    {
      return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(long value)
    {
      if (value < 0L)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt64"));
      else
        return (ulong) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(ulong value)
    {
      return value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(float value)
    {
      return Convert.ToUInt64((double) value);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(double value)
    {
      return checked ((ulong) Math.Round(value));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(Decimal value)
    {
      return Decimal.ToUInt64(Decimal.Round(value, 0));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(string value)
    {
      if (value == null)
        return 0UL;
      else
        return ulong.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0UL;
      else
        return ulong.Parse(value, NumberStyles.Integer, provider);
    }

    [CLSCompliant(false)]
    public static ulong ToUInt64(DateTime value)
    {
      return ((IConvertible) value).ToUInt64((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static float ToSingle(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToSingle((IFormatProvider) null);
      else
        return 0.0f;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToSingle(provider);
      else
        return 0.0f;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static float ToSingle(sbyte value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(byte value)
    {
      return (float) value;
    }

    public static float ToSingle(char value)
    {
      return ((IConvertible) value).ToSingle((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static float ToSingle(short value)
    {
      return (float) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static float ToSingle(ushort value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(int value)
    {
      return (float) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static float ToSingle(uint value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(long value)
    {
      return (float) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static float ToSingle(ulong value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(float value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(double value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(Decimal value)
    {
      return (float) value;
    }

    [__DynamicallyInvokable]
    public static float ToSingle(string value)
    {
      if (value == null)
        return 0.0f;
      else
        return float.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static float ToSingle(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0.0f;
      else
        return float.Parse(value, NumberStyles.Float | NumberStyles.AllowThousands, provider);
    }

    [__DynamicallyInvokable]
    public static float ToSingle(bool value)
    {
      return value ? 1f : 0.0f;
    }

    public static float ToSingle(DateTime value)
    {
      return ((IConvertible) value).ToSingle((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static double ToDouble(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToDouble((IFormatProvider) null);
      else
        return 0.0;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToDouble(provider);
      else
        return 0.0;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static double ToDouble(sbyte value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(byte value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(short value)
    {
      return (double) value;
    }

    public static double ToDouble(char value)
    {
      return ((IConvertible) value).ToDouble((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static double ToDouble(ushort value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(int value)
    {
      return (double) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static double ToDouble(uint value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(long value)
    {
      return (double) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static double ToDouble(ulong value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(float value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(double value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(Decimal value)
    {
      return (double) value;
    }

    [__DynamicallyInvokable]
    public static double ToDouble(string value)
    {
      if (value == null)
        return 0.0;
      else
        return double.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static double ToDouble(string value, IFormatProvider provider)
    {
      if (value == null)
        return 0.0;
      else
        return double.Parse(value, NumberStyles.Float | NumberStyles.AllowThousands, provider);
    }

    [__DynamicallyInvokable]
    public static double ToDouble(bool value)
    {
      return value ? 1.0 : 0.0;
    }

    public static double ToDouble(DateTime value)
    {
      return ((IConvertible) value).ToDouble((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToDecimal((IFormatProvider) null);
      else
        return new Decimal(0);
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToDecimal(provider);
      else
        return new Decimal(0);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static Decimal ToDecimal(sbyte value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(byte value)
    {
      return (Decimal) value;
    }

    public static Decimal ToDecimal(char value)
    {
      return ((IConvertible) value).ToDecimal((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(short value)
    {
      return (Decimal) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static Decimal ToDecimal(ushort value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(int value)
    {
      return (Decimal) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static Decimal ToDecimal(uint value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(long value)
    {
      return (Decimal) value;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static Decimal ToDecimal(ulong value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(float value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(double value)
    {
      return (Decimal) value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(string value)
    {
      if (value == null)
        return new Decimal(0);
      else
        return Decimal.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(string value, IFormatProvider provider)
    {
      if (value == null)
        return new Decimal(0);
      else
        return Decimal.Parse(value, NumberStyles.Number, provider);
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(Decimal value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static Decimal ToDecimal(bool value)
    {
      return (Decimal) (value ? 1 : 0);
    }

    public static Decimal ToDecimal(DateTime value)
    {
      return ((IConvertible) value).ToDecimal((IFormatProvider) null);
    }

    public static DateTime ToDateTime(DateTime value)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static DateTime ToDateTime(object value)
    {
      if (value != null)
        return ((IConvertible) value).ToDateTime((IFormatProvider) null);
      else
        return DateTime.MinValue;
    }

    [__DynamicallyInvokable]
    public static DateTime ToDateTime(object value, IFormatProvider provider)
    {
      if (value != null)
        return ((IConvertible) value).ToDateTime(provider);
      else
        return DateTime.MinValue;
    }

    [__DynamicallyInvokable]
    public static DateTime ToDateTime(string value)
    {
      if (value == null)
        return new DateTime(0L);
      else
        return DateTime.Parse(value, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static DateTime ToDateTime(string value, IFormatProvider provider)
    {
      if (value == null)
        return new DateTime(0L);
      else
        return DateTime.Parse(value, provider);
    }

    [CLSCompliant(false)]
    public static DateTime ToDateTime(sbyte value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(byte value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(short value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    public static DateTime ToDateTime(ushort value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(int value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    public static DateTime ToDateTime(uint value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(long value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    [CLSCompliant(false)]
    public static DateTime ToDateTime(ulong value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(bool value)
    {
      return ((IConvertible) (bool) (value ? 1 : 0)).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(char value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(float value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(double value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    public static DateTime ToDateTime(Decimal value)
    {
      return ((IConvertible) value).ToDateTime((IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public static string ToString(object value)
    {
      return Convert.ToString(value, (IFormatProvider) null);
    }

    [__DynamicallyInvokable]
    public static string ToString(object value, IFormatProvider provider)
    {
      IConvertible convertible = value as IConvertible;
      if (convertible != null)
        return convertible.ToString(provider);
      IFormattable formattable = value as IFormattable;
      if (formattable != null)
        return formattable.ToString((string) null, provider);
      if (value != null)
        return value.ToString();
      else
        return string.Empty;
    }

    [__DynamicallyInvokable]
    public static string ToString(bool value)
    {
      return value.ToString();
    }

    [__DynamicallyInvokable]
    public static string ToString(bool value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(char value)
    {
      return char.ToString(value);
    }

    [__DynamicallyInvokable]
    public static string ToString(char value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(sbyte value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(sbyte value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(byte value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(byte value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(short value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(short value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(ushort value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(ushort value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(int value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(int value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(uint value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(uint value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(long value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(long value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(ulong value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static string ToString(ulong value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(float value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(float value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(double value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(double value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(Decimal value)
    {
      return value.ToString((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public static string ToString(Decimal value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    [__DynamicallyInvokable]
    public static string ToString(DateTime value)
    {
      return value.ToString();
    }

    [__DynamicallyInvokable]
    public static string ToString(DateTime value, IFormatProvider provider)
    {
      return value.ToString(provider);
    }

    public static string ToString(string value)
    {
      return value;
    }

    public static string ToString(string value, IFormatProvider provider)
    {
      return value;
    }

    [__DynamicallyInvokable]
    public static byte ToByte(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      int num = ParseNumbers.StringToInt(value, fromBase, 4608);
      if (num < 0 || num > (int) byte.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
      else
        return (byte) num;
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static sbyte ToSByte(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      int num = ParseNumbers.StringToInt(value, fromBase, 5120);
      if (fromBase != 10 && num <= (int) byte.MaxValue || num >= (int) sbyte.MinValue && num <= (int) sbyte.MaxValue)
        return (sbyte) num;
      else
        throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
    }

    [__DynamicallyInvokable]
    public static short ToInt16(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      int num = ParseNumbers.StringToInt(value, fromBase, 6144);
      if (fromBase != 10 && num <= (int) ushort.MaxValue || num >= (int) short.MinValue && num <= (int) short.MaxValue)
        return (short) num;
      else
        throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ushort ToUInt16(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      int num = ParseNumbers.StringToInt(value, fromBase, 4608);
      if (num < 0 || num > (int) ushort.MaxValue)
        throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
      else
        return (ushort) num;
    }

    [__DynamicallyInvokable]
    public static int ToInt32(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.StringToInt(value, fromBase, 4096);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static uint ToUInt32(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return (uint) ParseNumbers.StringToInt(value, fromBase, 4608);
    }

    [__DynamicallyInvokable]
    public static long ToInt64(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.StringToLong(value, fromBase, 4096);
    }

    [CLSCompliant(false)]
    [__DynamicallyInvokable]
    public static ulong ToUInt64(string value, int fromBase)
    {
      if (fromBase != 2 && fromBase != 8 && (fromBase != 10 && fromBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return (ulong) ParseNumbers.StringToLong(value, fromBase, 4608);
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static string ToString(byte value, int toBase)
    {
      if (toBase != 2 && toBase != 8 && (toBase != 10 && toBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.IntToString((int) value, toBase, -1, ' ', 64);
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static string ToString(short value, int toBase)
    {
      if (toBase != 2 && toBase != 8 && (toBase != 10 && toBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.IntToString((int) value, toBase, -1, ' ', 128);
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static string ToString(int value, int toBase)
    {
      if (toBase != 2 && toBase != 8 && (toBase != 10 && toBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.IntToString(value, toBase, -1, ' ', 0);
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static string ToString(long value, int toBase)
    {
      if (toBase != 2 && toBase != 8 && (toBase != 10 && toBase != 16))
        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidBase"));
      else
        return ParseNumbers.LongToString(value, toBase, -1, ' ', 0);
    }

    [__DynamicallyInvokable]
    public static string ToBase64String(byte[] inArray)
    {
      if (inArray == null)
        throw new ArgumentNullException("inArray");
      else
        return Convert.ToBase64String(inArray, 0, inArray.Length, Base64FormattingOptions.None);
    }

    [ComVisible(false)]
    public static string ToBase64String(byte[] inArray, Base64FormattingOptions options)
    {
      if (inArray == null)
        throw new ArgumentNullException("inArray");
      else
        return Convert.ToBase64String(inArray, 0, inArray.Length, options);
    }

    [__DynamicallyInvokable]
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public static string ToBase64String(byte[] inArray, int offset, int length)
    {
      return Convert.ToBase64String(inArray, offset, length, Base64FormattingOptions.None);
    }

    [ComVisible(false)]
    [SecuritySafeCritical]
    public static unsafe string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
    {
      if (inArray == null)
        throw new ArgumentNullException("inArray");
      if (length < 0)
        throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (offset < 0)
        throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
      if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
      {
        throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", new object[1]
        {
          (object) options
        }));
      }
      else
      {
        int length1 = inArray.Length;
        if (offset > length1 - length)
          throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"));
        if (length1 == 0)
          return string.Empty;
        bool insertLineBreaks = options == Base64FormattingOptions.InsertLineBreaks;
        string str = string.FastAllocateString(Convert.ToBase64_CalculateAndValidateOutputLength(length, insertLineBreaks));
        fixed (char* outChars = str)
          fixed (byte* inData = inArray)
          {
            Convert.ConvertToBase64Array(outChars, inData, offset, length, insertLineBreaks);
            return str;
          }
      }
    }

    [__DynamicallyInvokable]
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
    {
      return Convert.ToBase64CharArray(inArray, offsetIn, length, outArray, offsetOut, Base64FormattingOptions.None);
    }

    [SecuritySafeCritical]
    [ComVisible(false)]
    public static unsafe int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options)
    {
      if (inArray == null)
        throw new ArgumentNullException("inArray");
      if (outArray == null)
        throw new ArgumentNullException("outArray");
      if (length < 0)
        throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (offsetIn < 0)
        throw new ArgumentOutOfRangeException("offsetIn", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
      if (offsetOut < 0)
        throw new ArgumentOutOfRangeException("offsetOut", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
      if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
      {
        throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", new object[1]
        {
          (object) options
        }));
      }
      else
      {
        int length1 = inArray.Length;
        if (offsetIn > length1 - length)
          throw new ArgumentOutOfRangeException("offsetIn", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"));
        if (length1 == 0)
          return 0;
        bool insertLineBreaks = options == Base64FormattingOptions.InsertLineBreaks;
        int length2 = outArray.Length;
        int num1 = Convert.ToBase64_CalculateAndValidateOutputLength(length, insertLineBreaks);
        if (offsetOut > length2 - num1)
          throw new ArgumentOutOfRangeException("offsetOut", Environment.GetResourceString("ArgumentOutOfRange_OffsetOut"));
        int num2;
        fixed (char* outChars = &outArray[offsetOut])
          fixed (byte* inData = inArray)
            num2 = Convert.ConvertToBase64Array(outChars, inData, offsetIn, length, insertLineBreaks);
        return num2;
      }
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static unsafe byte[] FromBase64String(string s)
    {
      if (s == null)
        throw new ArgumentNullException("s");
      fixed (char* inputPtr = s)
        return Convert.FromBase64CharPtr(inputPtr, s.Length);
    }

    [SecuritySafeCritical]
    [__DynamicallyInvokable]
    public static unsafe byte[] FromBase64CharArray(char[] inArray, int offset, int length)
    {
      if (inArray == null)
        throw new ArgumentNullException("inArray");
      if (length < 0)
        throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index"));
      if (offset < 0)
        throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
      if (offset > inArray.Length - length)
        throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"));
      fixed (char* chPtr = inArray)
        return Convert.FromBase64CharPtr(chPtr + offset, length);
    }

    [SecurityCritical]
    private static unsafe int ConvertToBase64Array(char* outChars, byte* inData, int offset, int length, bool insertLineBreaks)
    {
      int num1 = length % 3;
      int num2 = offset + (length - num1);
      int index1 = 0;
      int num3 = 0;
      fixed (char* chPtr1 = Convert.base64Table)
      {
        int index2 = offset;
        while (index2 < num2)
        {
          if (insertLineBreaks)
          {
            if (num3 == 76)
            {
              char* chPtr2 = outChars;
              int num4 = index1;
              int num5 = 1;
              int num6 = num4 + num5;
              IntPtr num7 = (IntPtr) num4 * 2;
              *(short*) ((IntPtr) chPtr2 + num7) = (short) 13;
              char* chPtr3 = outChars;
              int num8 = num6;
              int num9 = 1;
              index1 = num8 + num9;
              IntPtr num10 = (IntPtr) num8 * 2;
              *(short*) ((IntPtr) chPtr3 + num10) = (short) 10;
              num3 = 0;
            }
            num3 += 4;
          }
          outChars[index1] = chPtr1[((int) inData[index2] & 252) >> 2];
          outChars[index1 + 1] = chPtr1[((int) inData[index2] & 3) << 4 | ((int) inData[index2 + 1] & 240) >> 4];
          outChars[index1 + 2] = chPtr1[((int) inData[index2 + 1] & 15) << 2 | ((int) inData[index2 + 2] & 192) >> 6];
          outChars[index1 + 3] = chPtr1[(int) inData[index2 + 2] & 63];
          index1 += 4;
          index2 += 3;
        }
        int index3 = num2;
        if (insertLineBreaks && num1 != 0 && num3 == 76)
        {
          char* chPtr2 = outChars;
          int num4 = index1;
          int num5 = 1;
          int num6 = num4 + num5;
          IntPtr num7 = (IntPtr) num4 * 2;
          *(short*) ((IntPtr) chPtr2 + num7) = (short) 13;
          char* chPtr3 = outChars;
          int num8 = num6;
          int num9 = 1;
          index1 = num8 + num9;
          IntPtr num10 = (IntPtr) num8 * 2;
          *(short*) ((IntPtr) chPtr3 + num10) = (short) 10;
        }
        switch (num1)
        {
          case 1:
            outChars[index1] = chPtr1[((int) inData[index3] & 252) >> 2];
            outChars[index1 + 1] = chPtr1[((int) inData[index3] & 3) << 4];
            outChars[index1 + 2] = chPtr1[64];
            outChars[index1 + 3] = chPtr1[64];
            index1 += 4;
            break;
          case 2:
            outChars[index1] = chPtr1[((int) inData[index3] & 252) >> 2];
            outChars[index1 + 1] = chPtr1[((int) inData[index3] & 3) << 4 | ((int) inData[index3 + 1] & 240) >> 4];
            outChars[index1 + 2] = chPtr1[((int) inData[index3 + 1] & 15) << 2];
            outChars[index1 + 3] = chPtr1[64];
            index1 += 4;
            break;
        }
      }
      return index1;
    }

    private static int ToBase64_CalculateAndValidateOutputLength(int inputLength, bool insertLineBreaks)
    {
      long num1 = (long) inputLength / 3L * 4L + (inputLength % 3 != 0 ? 4L : 0L);
      if (num1 == 0L)
        return 0;
      if (insertLineBreaks)
      {
        long num2 = num1 / 76L;
        if (num1 % 76L == 0L)
          --num2;
        num1 += num2 * 2L;
      }
      if (num1 > (long) int.MaxValue)
        throw new OutOfMemoryException();
      else
        return (int) num1;
    }

    [SecurityCritical]
    private static unsafe byte[] FromBase64CharPtr(char* inputPtr, int inputLength)
    {
      for (; inputLength > 0; --inputLength)
      {
        switch (inputPtr[inputLength - 1])
        {
          case ' ':
          case '\n':
          case '\r':
          case '\t':
            goto case 32;
          default:
            goto label_4;
        }
      }
label_4:
      int resultLength = Convert.FromBase64_ComputeResultLength(inputPtr, inputLength);
      byte[] numArray = new byte[resultLength];
      fixed (byte* startDestPtr = numArray)
        Convert.FromBase64_Decode(inputPtr, inputLength, startDestPtr, resultLength);
      return numArray;
    }

    [SecurityCritical]
    private static unsafe int FromBase64_Decode(char* startInputPtr, int inputLength, byte* startDestPtr, int destLength)
    {
      char* chPtr1 = startInputPtr;
      byte* numPtr1 = startDestPtr;
      char* chPtr2 = chPtr1 + inputLength;
      byte* numPtr2 = numPtr1 + destLength;
      uint num1 = (uint) byte.MaxValue;
      while (chPtr1 < chPtr2)
      {
        uint num2 = (uint) *chPtr1;
        ++chPtr1;
        uint num3;
        if (num2 - 65U <= 25U)
          num3 = num2 - 65U;
        else if (num2 - 97U <= 25U)
          num3 = num2 - 71U;
        else if (num2 - 48U <= 9U)
        {
          num3 = num2 - 4294967292U;
        }
        else
        {
          uint num4 = num2;
          if (num4 <= 32U)
          {
            switch (num4)
            {
              case 9U:
              case 10U:
              case 13U:
              case 32U:
                continue;
            }
          }
          else if ((int) num4 != 43)
          {
            if ((int) num4 != 47)
            {
              if ((int) num4 == 61)
              {
                if (chPtr1 == chPtr2)
                {
                  uint num5 = num1 << 6;
                  if (((int) num5 & int.MinValue) == 0)
                    throw new FormatException(Environment.GetResourceString("Format_BadBase64CharArrayLength"));
                  if ((int) (numPtr2 - numPtr1) < 2)
                    return -1;
                  byte* numPtr3 = numPtr1;
                  IntPtr num6 = IntPtr(1);
                  byte* numPtr4 = numPtr3 + num6.ToInt64();
                  int num7 = (int) (byte) (num5 >> 16);
                  *numPtr3 = (byte) num7;
                  byte* numPtr5 = numPtr4;
                  IntPtr num8 = IntPtr(1);
                  numPtr1 = numPtr5 + num8.ToInt64();
                  int num9 = (int) (byte) (num5 >> 8);
                  *numPtr5 = (byte) num9;
                  num1 = (uint) byte.MaxValue;
                  break;
                }
                else
                {
                  for (; chPtr1 < chPtr2 - 1; ++chPtr1)
                  {
                    switch (*chPtr1)
                    {
                      case ' ':
                      case '\n':
                      case '\r':
                      case '\t':
                        goto case 32;
                      default:
                        goto label_29;
                    }
                  }
label_29:
                  if (chPtr1 != chPtr2 - 1 || (int) *chPtr1 != 61)
                    throw new FormatException(Environment.GetResourceString("Format_BadBase64Char"));
                  uint num5 = num1 << 12;
                  if (((int) num5 & int.MinValue) == 0)
                    throw new FormatException(Environment.GetResourceString("Format_BadBase64CharArrayLength"));
                  if ((int) (numPtr2 - numPtr1) < 1)
                    return -1;
                  *numPtr1++ = (byte) (num5 >> 16);
                  num1 = (uint) byte.MaxValue;
                  break;
                }
              }
            }
            else
            {
              num3 = 63U;
              goto label_16;
            }
          }
          else
          {
            num3 = 62U;
            goto label_16;
          }
          throw new FormatException(Environment.GetResourceString("Format_BadBase64Char"));
        }
label_16:
        num1 = num1 << 6 | num3;
        if (((int) num1 & int.MinValue) != 0)
        {
          if ((int) (numPtr2 - numPtr1) < 3)
            return -1;
          *numPtr1 = (byte) (num1 >> 16);
          numPtr1[1] = (byte) (num1 >> 8);
          numPtr1[2] = (byte) num1;
          numPtr1 += 3;
          num1 = (uint) byte.MaxValue;
        }
      }
      if ((int) num1 != (int) byte.MaxValue)
        throw new FormatException(Environment.GetResourceString("Format_BadBase64CharArrayLength"));
      else
        return (int) (numPtr1 - startDestPtr);
    }

    [SecurityCritical]
    private static unsafe int FromBase64_ComputeResultLength(char* inputPtr, int inputLength)
    {
      char* chPtr = inputPtr + inputLength;
      int num1 = inputLength;
      int num2 = 0;
      while (inputPtr < chPtr)
      {
        uint num3 = (uint) *inputPtr;
        ++inputPtr;
        if (num3 <= 32U)
          --num1;
        else if ((int) num3 == 61)
        {
          --num1;
          ++num2;
        }
      }
      if (num2 != 0)
      {
        if (num2 == 1)
        {
          num2 = 2;
        }
        else
        {
          if (num2 != 2)
            throw new FormatException(Environment.GetResourceString("Format_BadBase64Char"));
          num2 = 1;
        }
      }
      return num1 / 4 * 3 + num2;
    }
  }
}