< Summary

Information
Line coverage
6%
Covered lines: 58
Uncovered lines: 776
Coverable lines: 834
Total lines: 2949
Line coverage: 6.9%
Branch coverage
3%
Covered branches: 20
Total branches: 588
Branch coverage: 3.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
GetTypeCode(...)0%440%
IsDBNull(...)0%440%
ChangeType(...)100%110%
ChangeType(...)0%30300%
DefaultToType(...)0%40400%
ChangeType(...)100%110%
ChangeType(...)0%40400%
ThrowCharOverflowException()100%110%
ThrowByteOverflowException()100%110%
ThrowSByteOverflowException()100%110%
ThrowInt16OverflowException()100%110%
ThrowUInt16OverflowException()100%110%
ThrowInt32OverflowException()100%110%
ThrowUInt32OverflowException()100%110%
ThrowInt64OverflowException()100%110%
ThrowUInt64OverflowException()100%110%
ToBoolean(...)0%220%
ToBoolean(...)0%220%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)0%220%
ToBoolean(...)0%220%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToBoolean(...)100%110%
ToChar(...)0%220%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)100%110%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)100%110%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)0%220%
ToChar(...)100%110%
ToChar(...)100%110%
ToChar(...)100%110%
ToChar(...)100%110%
ToSByte(...)0%220%
ToSByte(...)0%220%
ToSByte(...)100%110%
ToSByte(...)100%110%
ToSByte(...)0%220%
ToSByte(...)0%220%
ToSByte(...)0%440%
ToSByte(...)0%220%
ToSByte(...)0%440%
ToSByte(...)0%220%
ToSByte(...)0%440%
ToSByte(...)0%220%
ToSByte(...)100%110%
ToSByte(...)100%110%
ToSByte(...)100%110%
ToSByte(...)0%220%
ToSByte(...)100%110%
ToSByte(...)100%110%
ToByte(...)0%220%
ToByte(...)0%220%
ToByte(...)100%110%
ToByte(...)100%110%
ToByte(...)0%220%
ToByte(...)0%220%
ToByte(...)0%220%
ToByte(...)0%220%
ToByte(...)100%110%
ToByte(...)0%220%
ToByte(...)100%110%
ToByte(...)0%220%
ToByte(...)100%110%
ToByte(...)100%110%
ToByte(...)100%110%
ToByte(...)0%220%
ToByte(...)0%220%
ToByte(...)100%110%
ToInt16(...)0%220%
ToInt16(...)0%220%
ToInt16(...)100%110%
ToInt16(...)0%220%
ToInt16(...)100%110%
ToInt16(...)100%110%
ToInt16(...)0%220%
ToInt16(...)0%440%
ToInt16(...)0%220%
ToInt16(...)100%110%
ToInt16(...)0%440%
ToInt16(...)0%220%
ToInt16(...)100%110%
ToInt16(...)100%110%
ToInt16(...)100%110%
ToInt16(...)0%220%
ToInt16(...)0%220%
ToInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToUInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToUInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToUInt16(...)100%110%
ToUInt16(...)100%110%
ToUInt16(...)0%220%
ToUInt16(...)0%220%
ToUInt16(...)100%110%
ToInt32(...)0%220%
ToInt32(...)0%220%
ToInt32(...)100%110%
ToInt32(...)100%110%
ToInt32(...)100%110%
ToInt32(...)100%110%
ToInt32(...)100%110%
ToInt32(...)100%110%
ToInt32(...)0%220%
ToInt32(...)100%110%
ToInt32(...)0%440%
ToInt32(...)0%220%
ToInt32(...)100%110%
ToInt32(...)0%18180%
ToInt32(...)100%110%
ToInt32(...)0%220%
ToInt32(...)0%220%
ToInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToUInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToUInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToUInt32(...)0%10100%
ToUInt32(...)100%110%
ToUInt32(...)0%220%
ToUInt32(...)0%220%
ToUInt32(...)100%110%
ToInt64(...)0%220%
ToInt64(...)0%220%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)0%220%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)100%110%
ToInt64(...)0%220%
ToInt64(...)0%220%
ToInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToUInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToUInt64(...)100%110%
ToUInt64(...)100%110%
ToUInt64(...)100%110%
ToUInt64(...)0%220%
ToUInt64(...)0%220%
ToUInt64(...)100%110%
ToSingle(...)0%220%
ToSingle(...)0%220%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToSingle(...)0%220%
ToSingle(...)0%220%
ToSingle(...)100%110%
ToSingle(...)100%110%
ToDouble(...)0%220%
ToDouble(...)0%220%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDouble(...)0%220%
ToDouble(...)0%220%
ToDouble(...)100%110%
ToDouble(...)100%110%
ToDecimal(...)0%220%
ToDecimal(...)0%220%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)0%220%
ToDecimal(...)0%220%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDecimal(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)0%220%
ToDateTime(...)0%220%
ToDateTime(...)0%220%
ToDateTime(...)0%220%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToDateTime(...)100%110%
ToString(...)100%110%
ToString(...)0%660%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToString(...)100%110%
ToByte(...)0%12120%
ToSByte(...)0%18180%
ToInt16(...)0%18180%
ToUInt16(...)0%12120%
ToInt32(...)0%10100%
ToUInt32(...)0%10100%
ToInt64(...)0%10100%
ToUInt64(...)0%10100%
ToString(...)100%110%
ToString(...)0%10100%
ToString(...)0%10100%
ToString(...)0%10100%
ThrowInvalidBase()100%110%
ToOctalString(...)0%220%
ToBase64String(...)100%110%
ToBase64String(...)100%110%
ToBase64String(...)100%110%
ToBase64String(...)100%110%
ToBase64String(...)62.5%8884.61%
ToBase64CharArray(...)100%110%
ToBase64CharArray(...)62.5%8890.47%
TryToBase64Chars(...)0%880%
ConvertToBase64WithLineBreaks(...)75%44100%
ToBase64_CalculateAndValidateOutputLength(...)75%8881.81%
FromBase64String(...)50%2266.66%
TryFromBase64String(...)0%220%
TryFromBase64Chars(...)0%220%
FromBase64CharArray(...)100%11100%
FromHexString(...)0%220%
FromHexString(...)0%660%
FromHexString(...)0%660%
FromHexString(...)100%110%
FromHexString(...)0%10100%
FromHexString(...)0%10100%
ToHexString(...)100%110%
ToHexString(...)100%110%
ToHexString(...)0%220%
TryToHexString(...)0%660%
TryToHexString(...)0%660%
ToHexStringLower(...)100%110%
ToHexStringLower(...)100%110%
ToHexStringLower(...)0%220%
TryToHexStringLower(...)0%660%
TryToHexStringLower(...)0%660%

File(s)

C:\h\w\B7B10A05\w\A2F5091A\e\runtime-utils\Runner\runtime\src\libraries\System.Private.CoreLib\src\System\Convert.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Buffers;
 5using System.Buffers.Text;
 6using System.Diagnostics;
 7using System.Diagnostics.CodeAnalysis;
 8using System.Globalization;
 9using System.Runtime.CompilerServices;
 10using System.Runtime.InteropServices;
 11using System.Runtime.Intrinsics;
 12using System.Text;
 13
 14namespace System
 15{
 16    [Flags]
 17    public enum Base64FormattingOptions
 18    {
 19        None = 0,
 20        InsertLineBreaks = 1
 21    }
 22
 23    // The Convert class provides conversion and querying methods for values. The
 24    // Convert class contains static members only, and it is not possible to create
 25    // instances of the class.
 26    //
 27    // The statically typed conversion methods provided by the Convert class are all
 28    // of the form:
 29    //
 30    //    public static XXX ToXXX(YYY value)
 31    //
 32    // where XXX is the target type and YYY is the source type. The matrix below
 33    // shows the set of supported conversions. The set of conversions is symmetric
 34    // such that for every ToXXX(YYY) there is also a ToYYY(XXX).
 35    //
 36    // From:  To: Bol Chr SBy Byt I16 U16 I32 U32 I64 U64 Sgl Dbl Dec Dat Str
 37    // ----------------------------------------------------------------------
 38    // Boolean     x       x   x   x   x   x   x   x   x   x   x   x       x
 39    // Char            x   x   x   x   x   x   x   x   x                   x
 40    // SByte       x   x   x   x   x   x   x   x   x   x   x   x   x       x
 41    // Byte        x   x   x   x   x   x   x   x   x   x   x   x   x       x
 42    // Int16       x   x   x   x   x   x   x   x   x   x   x   x   x       x
 43    // UInt16      x   x   x   x   x   x   x   x   x   x   x   x   x       x
 44    // Int32       x   x   x   x   x   x   x   x   x   x   x   x   x       x
 45    // UInt32      x   x   x   x   x   x   x   x   x   x   x   x   x       x
 46    // Int64       x   x   x   x   x   x   x   x   x   x   x   x   x       x
 47    // UInt64      x   x   x   x   x   x   x   x   x   x   x   x   x       x
 48    // Single      x       x   x   x   x   x   x   x   x   x   x   x       x
 49    // Double      x       x   x   x   x   x   x   x   x   x   x   x       x
 50    // Decimal     x       x   x   x   x   x   x   x   x   x   x   x       x
 51    // DateTime                                                        x   x
 52    // String      x   x   x   x   x   x   x   x   x   x   x   x   x   x   x
 53    // ----------------------------------------------------------------------
 54    //
 55    // For dynamic conversions, the Convert class provides a set of methods of the
 56    // form:
 57    //
 58    //    public static XXX ToXXX(object value)
 59    //
 60    // where XXX is the target type (Boolean, Char, SByte, Byte, Int16, UInt16,
 61    // Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime,
 62    // or String). The implementations of these methods all take the form:
 63    //
 64    //    public static XXX toXXX(object value) {
 65    //        return value == null? XXX.Default: ((IConvertible)value).ToXXX();
 66    //    }
 67    //
 68    // The code first checks if the given value is a null reference (which is the
 69    // same as TypeCode.Empty), in which case it returns the default value for type
 70    // XXX. Otherwise, a cast to IConvertible is performed, and the appropriate ToXXX()
 71    // method is invoked on the object. An InvalidCastException is thrown if the
 72    // cast to IConvertible fails, and that exception is simply allowed to propagate out
 73    // of the conversion method.
 74
 75    public static partial class Convert
 76    {
 77        private const int Base64LineBreakPosition = 76;
 78
 79        // Constant representing the database null value. This value is used in
 80        // database applications to indicate the absence of a known value. Note
 81        // that Convert.DBNull is NOT the same as a null object reference, which is
 82        // represented by TypeCode.Empty.
 83        //
 84        // When passed Convert.DBNull, the Convert.GetTypeCode() method returns
 85        // TypeCode.DBNull.
 86        //
 87        // When passed Convert.DBNull, all the Convert.ToXXX() methods except ToString()
 88        // throw an InvalidCastException.
 089        public static readonly object DBNull = System.DBNull.Value;
 90
 91        // Returns the type code for the given object. If the argument is null,
 92        // the result is TypeCode.Empty. If the argument is not a value (i.e. if
 93        // the object does not implement IConvertible), the result is TypeCode.Object.
 94        // Otherwise, the result is the type code of the object, as determined by
 95        // the object's implementation of IConvertible.
 96        public static TypeCode GetTypeCode(object? value)
 97        {
 098            if (value == null) return TypeCode.Empty;
 099            if (value is IConvertible temp)
 100            {
 0101                return temp.GetTypeCode();
 102            }
 0103            return TypeCode.Object;
 104        }
 105
 106        // Returns true if the given object is a database null. This operation
 107        // corresponds to "value.GetTypeCode() == TypeCode.DBNull".
 108        public static bool IsDBNull([NotNullWhen(true)] object? value)
 109        {
 0110            if (value == System.DBNull.Value) return true;
 0111            return value is IConvertible convertible ? convertible.GetTypeCode() == TypeCode.DBNull : false;
 112        }
 113
 114        // Converts the given object to the given type. In general, this method is
 115        // equivalent to calling ((IConvertible)value).ToXXX(CultureInfo.CurrentCulture) for the given
 116        // typeCode and boxing the result.
 117        //
 118        // The method first checks if the given object implements IConvertible. If not,
 119        // the only permitted conversion is from a null to TypeCode.Empty/TypeCode.String/TypeCode.Object, the
 120        // result of which is null.
 121        [return: NotNullIfNotNull(nameof(value))]
 122        public static object? ChangeType(object? value, TypeCode typeCode)
 123        {
 0124            return ChangeType(value, typeCode, CultureInfo.CurrentCulture);
 125        }
 126
 127        [return: NotNullIfNotNull(nameof(value))]
 128        public static object? ChangeType(object? value, TypeCode typeCode, IFormatProvider? provider)
 129        {
 0130            if (value == null && (typeCode == TypeCode.Empty || typeCode == TypeCode.String || typeCode == TypeCode.Obje
 131            {
 0132                return null;
 133            }
 134
 0135            if (value is not IConvertible v)
 136            {
 0137                throw new InvalidCastException(SR.InvalidCast_IConvertible);
 138            }
 139
 140            // This line is invalid for things like Enums that return a TypeCode
 141            // of int, but the object can't actually be cast to an int.
 142            //            if (v.GetTypeCode() == typeCode) return value;
 0143            return typeCode switch
 0144            {
 0145                TypeCode.Boolean => v.ToBoolean(provider),
 0146                TypeCode.Char => v.ToChar(provider),
 0147                TypeCode.SByte => v.ToSByte(provider),
 0148                TypeCode.Byte => v.ToByte(provider),
 0149                TypeCode.Int16 => v.ToInt16(provider),
 0150                TypeCode.UInt16 => v.ToUInt16(provider),
 0151                TypeCode.Int32 => v.ToInt32(provider),
 0152                TypeCode.UInt32 => v.ToUInt32(provider),
 0153                TypeCode.Int64 => v.ToInt64(provider),
 0154                TypeCode.UInt64 => v.ToUInt64(provider),
 0155                TypeCode.Single => v.ToSingle(provider),
 0156                TypeCode.Double => v.ToDouble(provider),
 0157                TypeCode.Decimal => v.ToDecimal(provider),
 0158                TypeCode.DateTime => v.ToDateTime(provider),
 0159                TypeCode.String => v.ToString(provider),
 0160                TypeCode.Object => value,
 0161                TypeCode.DBNull => throw new InvalidCastException(SR.InvalidCast_DBNull),
 0162                TypeCode.Empty => throw new InvalidCastException(SR.InvalidCast_Empty),
 0163                _ => throw new ArgumentException(SR.Arg_UnknownTypeCode),
 0164            };
 165        }
 166
 167        internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider? provider)
 168        {
 0169            ArgumentNullException.ThrowIfNull(targetType);
 170
 0171            Debug.Assert(value != null, "[Convert.DefaultToType]value!=null");
 172
 0173            if (ReferenceEquals(value.GetType(), targetType))
 174            {
 0175                return value;
 176            }
 177
 0178            if (ReferenceEquals(targetType, typeof(bool)))
 0179                return value.ToBoolean(provider);
 0180            if (ReferenceEquals(targetType, typeof(char)))
 0181                return value.ToChar(provider);
 0182            if (ReferenceEquals(targetType, typeof(sbyte)))
 0183                return value.ToSByte(provider);
 0184            if (ReferenceEquals(targetType, typeof(byte)))
 0185                return value.ToByte(provider);
 0186            if (ReferenceEquals(targetType, typeof(short)))
 0187                return value.ToInt16(provider);
 0188            if (ReferenceEquals(targetType, typeof(ushort)))
 0189                return value.ToUInt16(provider);
 0190            if (ReferenceEquals(targetType, typeof(int)))
 0191                return value.ToInt32(provider);
 0192            if (ReferenceEquals(targetType, typeof(uint)))
 0193                return value.ToUInt32(provider);
 0194            if (ReferenceEquals(targetType, typeof(long)))
 0195                return value.ToInt64(provider);
 0196            if (ReferenceEquals(targetType, typeof(ulong)))
 0197                return value.ToUInt64(provider);
 0198            if (ReferenceEquals(targetType, typeof(float)))
 0199                return value.ToSingle(provider);
 0200            if (ReferenceEquals(targetType, typeof(double)))
 0201                return value.ToDouble(provider);
 0202            if (ReferenceEquals(targetType, typeof(decimal)))
 0203                return value.ToDecimal(provider);
 0204            if (ReferenceEquals(targetType, typeof(DateTime)))
 0205                return value.ToDateTime(provider);
 0206            if (ReferenceEquals(targetType, typeof(string)))
 0207                return value.ToString(provider);
 0208            if (ReferenceEquals(targetType, typeof(object)))
 0209                return (object)value;
 210            // Need to special case Enum because typecode will be underlying type, e.g. Int32
 0211            if (ReferenceEquals(targetType, typeof(Enum)))
 0212                return (Enum)value;
 0213            if (ReferenceEquals(targetType, typeof(DBNull)))
 0214                throw new InvalidCastException(SR.InvalidCast_DBNull);
 0215            if (ReferenceEquals(targetType, typeof(Empty)))
 0216                throw new InvalidCastException(SR.InvalidCast_Empty);
 217
 0218            throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().FullName, targetType.FullNam
 219        }
 220
 221        [return: NotNullIfNotNull(nameof(value))]
 222        public static object? ChangeType(object? value, Type conversionType)
 223        {
 0224            return ChangeType(value, conversionType, CultureInfo.CurrentCulture);
 225        }
 226
 227        [return: NotNullIfNotNull(nameof(value))]
 228        public static object? ChangeType(object? value, Type conversionType, IFormatProvider? provider)
 229        {
 0230            ArgumentNullException.ThrowIfNull(conversionType);
 231
 0232            if (value == null)
 233            {
 0234                if (conversionType.IsValueType)
 235                {
 0236                    throw new InvalidCastException(SR.InvalidCast_CannotCastNullToValueType);
 237                }
 0238                return null;
 239            }
 240
 0241            if (value is not IConvertible ic)
 242            {
 0243                if (value.GetType() == conversionType)
 244                {
 0245                    return value;
 246                }
 0247                throw new InvalidCastException(SR.InvalidCast_IConvertible);
 248            }
 249
 0250            if (ReferenceEquals(conversionType, typeof(bool)))
 0251                return ic.ToBoolean(provider);
 0252            if (ReferenceEquals(conversionType, typeof(char)))
 0253                return ic.ToChar(provider);
 0254            if (ReferenceEquals(conversionType, typeof(sbyte)))
 0255                return ic.ToSByte(provider);
 0256            if (ReferenceEquals(conversionType, typeof(byte)))
 0257                return ic.ToByte(provider);
 0258            if (ReferenceEquals(conversionType, typeof(short)))
 0259                return ic.ToInt16(provider);
 0260            if (ReferenceEquals(conversionType, typeof(ushort)))
 0261                return ic.ToUInt16(provider);
 0262            if (ReferenceEquals(conversionType, typeof(int)))
 0263                return ic.ToInt32(provider);
 0264            if (ReferenceEquals(conversionType, typeof(uint)))
 0265                return ic.ToUInt32(provider);
 0266            if (ReferenceEquals(conversionType, typeof(long)))
 0267                return ic.ToInt64(provider);
 0268            if (ReferenceEquals(conversionType, typeof(ulong)))
 0269                return ic.ToUInt64(provider);
 0270            if (ReferenceEquals(conversionType, typeof(float)))
 0271                return ic.ToSingle(provider);
 0272            if (ReferenceEquals(conversionType, typeof(double)))
 0273                return ic.ToDouble(provider);
 0274            if (ReferenceEquals(conversionType, typeof(decimal)))
 0275                return ic.ToDecimal(provider);
 0276            if (ReferenceEquals(conversionType, typeof(DateTime)))
 0277                return ic.ToDateTime(provider);
 0278            if (ReferenceEquals(conversionType, typeof(string)))
 0279                return ic.ToString(provider);
 0280            if (ReferenceEquals(conversionType, typeof(object)))
 0281                return (object)value;
 282
 0283            return ic.ToType(conversionType, provider);
 284        }
 285
 286        [DoesNotReturn]
 0287        private static void ThrowCharOverflowException() { throw new OverflowException(SR.Overflow_Char); }
 288
 289        [DoesNotReturn]
 0290        private static void ThrowByteOverflowException() { throw new OverflowException(SR.Overflow_Byte); }
 291
 292        [DoesNotReturn]
 0293        private static void ThrowSByteOverflowException() { throw new OverflowException(SR.Overflow_SByte); }
 294
 295        [DoesNotReturn]
 0296        private static void ThrowInt16OverflowException() { throw new OverflowException(SR.Overflow_Int16); }
 297
 298        [DoesNotReturn]
 0299        private static void ThrowUInt16OverflowException() { throw new OverflowException(SR.Overflow_UInt16); }
 300
 301        [DoesNotReturn]
 0302        private static void ThrowInt32OverflowException() { throw new OverflowException(SR.Overflow_Int32); }
 303
 304        [DoesNotReturn]
 0305        private static void ThrowUInt32OverflowException() { throw new OverflowException(SR.Overflow_UInt32); }
 306
 307        [DoesNotReturn]
 0308        private static void ThrowInt64OverflowException() { throw new OverflowException(SR.Overflow_Int64); }
 309
 310        [DoesNotReturn]
 0311        private static void ThrowUInt64OverflowException() { throw new OverflowException(SR.Overflow_UInt64); }
 312
 313        // Conversions to Boolean
 314        public static bool ToBoolean([NotNullWhen(true)] object? value)
 315        {
 0316            return value != null && ((IConvertible)value).ToBoolean(null);
 317        }
 318
 319        public static bool ToBoolean([NotNullWhen(true)] object? value, IFormatProvider? provider)
 320        {
 0321            return value != null && ((IConvertible)value).ToBoolean(provider);
 322        }
 323
 324        public static bool ToBoolean(bool value)
 325        {
 0326            return value;
 327        }
 328
 329        [CLSCompliant(false)]
 330        public static bool ToBoolean(sbyte value)
 331        {
 0332            return value != 0;
 333        }
 334
 335        // To be consistent with IConvertible in the base data types else we get different semantics
 336        // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
 337        public static bool ToBoolean(char value)
 338        {
 0339            return ((IConvertible)value).ToBoolean(null);
 340        }
 341
 342        public static bool ToBoolean(byte value)
 343        {
 0344            return value != 0;
 345        }
 346
 347        public static bool ToBoolean(short value)
 348        {
 0349            return value != 0;
 350        }
 351
 352        [CLSCompliant(false)]
 353        public static bool ToBoolean(ushort value)
 354        {
 0355            return value != 0;
 356        }
 357
 358        public static bool ToBoolean(int value)
 359        {
 0360            return value != 0;
 361        }
 362
 363        [CLSCompliant(false)]
 364        public static bool ToBoolean(uint value)
 365        {
 0366            return value != 0;
 367        }
 368
 369        public static bool ToBoolean(long value)
 370        {
 0371            return value != 0;
 372        }
 373
 374        [CLSCompliant(false)]
 375        public static bool ToBoolean(ulong value)
 376        {
 0377            return value != 0;
 378        }
 379
 380        public static bool ToBoolean([NotNullWhen(true)] string? value)
 381        {
 0382            if (value == null)
 0383                return false;
 0384            return bool.Parse(value);
 385        }
 386
 387        public static bool ToBoolean([NotNullWhen(true)] string? value, IFormatProvider? provider)
 388        {
 0389            if (value == null)
 0390                return false;
 0391            return bool.Parse(value);
 392        }
 393
 394        public static bool ToBoolean(float value)
 395        {
 0396            return value != 0;
 397        }
 398
 399        public static bool ToBoolean(double value)
 400        {
 0401            return value != 0;
 402        }
 403
 404        public static bool ToBoolean(decimal value)
 405        {
 0406            return value != 0;
 407        }
 408
 409        public static bool ToBoolean(DateTime value)
 410        {
 0411            return ((IConvertible)value).ToBoolean(null);
 412        }
 413
 414        // Disallowed conversions to Boolean
 415        // public static bool ToBoolean(TimeSpan value)
 416
 417        // Conversions to Char
 418
 419        public static char ToChar(object? value)
 420        {
 0421            return value == null ? (char)0 : ((IConvertible)value).ToChar(null);
 422        }
 423
 424        public static char ToChar(object? value, IFormatProvider? provider)
 425        {
 0426            return value == null ? (char)0 : ((IConvertible)value).ToChar(provider);
 427        }
 428
 429        public static char ToChar(bool value)
 430        {
 0431            return ((IConvertible)value).ToChar(null);
 432        }
 433
 434        public static char ToChar(char value)
 435        {
 0436            return value;
 437        }
 438
 439        [CLSCompliant(false)]
 440        public static char ToChar(sbyte value)
 441        {
 0442            if (value < 0) ThrowCharOverflowException();
 0443            return (char)value;
 444        }
 445
 446        public static char ToChar(byte value)
 447        {
 0448            return (char)value;
 449        }
 450
 451        public static char ToChar(short value)
 452        {
 0453            if (value < 0) ThrowCharOverflowException();
 0454            return (char)value;
 455        }
 456
 457        [CLSCompliant(false)]
 458        public static char ToChar(ushort value)
 459        {
 0460            return (char)value;
 461        }
 462
 0463        public static char ToChar(int value) => ToChar((uint)value);
 464
 465        [CLSCompliant(false)]
 466        public static char ToChar(uint value)
 467        {
 0468            if (value > char.MaxValue) ThrowCharOverflowException();
 0469            return (char)value;
 470        }
 471
 0472        public static char ToChar(long value) => ToChar((ulong)value);
 473
 474        [CLSCompliant(false)]
 475        public static char ToChar(ulong value)
 476        {
 0477            if (value > char.MaxValue) ThrowCharOverflowException();
 0478            return (char)value;
 479        }
 480
 481        //
 482        // @VariantSwitch
 483        // Remove FormatExceptions;
 484        //
 485        public static char ToChar(string value)
 486        {
 0487            return ToChar(value, null);
 488        }
 489
 490        public static char ToChar(string value, IFormatProvider? provider)
 491        {
 0492            ArgumentNullException.ThrowIfNull(value);
 493
 0494            if (value.Length != 1)
 0495                throw new FormatException(SR.Format_NeedSingleChar);
 496
 0497            return value[0];
 498        }
 499
 500        // To be consistent with IConvertible in the base data types else we get different semantics
 501        // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
 502        public static char ToChar(float value)
 503        {
 0504            return ((IConvertible)value).ToChar(null);
 505        }
 506
 507        // To be consistent with IConvertible in the base data types else we get different semantics
 508        // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
 509        public static char ToChar(double value)
 510        {
 0511            return ((IConvertible)value).ToChar(null);
 512        }
 513
 514        // To be consistent with IConvertible in the base data types else we get different semantics
 515        // with widening operations. Without this operator this widen succeeds,with this API the widening throws.
 516        public static char ToChar(decimal value)
 517        {
 0518            return ((IConvertible)value).ToChar(null);
 519        }
 520
 521        public static char ToChar(DateTime value)
 522        {
 0523            return ((IConvertible)value).ToChar(null);
 524        }
 525
 526        // Disallowed conversions to Char
 527        // public static char ToChar(TimeSpan value)
 528
 529        // Conversions to SByte
 530
 531        [CLSCompliant(false)]
 532        public static sbyte ToSByte(object? value)
 533        {
 0534            return value == null ? (sbyte)0 : ((IConvertible)value).ToSByte(null);
 535        }
 536
 537        [CLSCompliant(false)]
 538        public static sbyte ToSByte(object? value, IFormatProvider? provider)
 539        {
 0540            return value == null ? (sbyte)0 : ((IConvertible)value).ToSByte(provider);
 541        }
 542
 543        [CLSCompliant(false)]
 544        public static sbyte ToSByte(bool value)
 545        {
 0546            return value ? (sbyte)bool.True : (sbyte)bool.False;
 547        }
 548
 549        [CLSCompliant(false)]
 550        public static sbyte ToSByte(sbyte value)
 551        {
 0552            return value;
 553        }
 554
 555        [CLSCompliant(false)]
 556        public static sbyte ToSByte(char value)
 557        {
 0558            if (value > sbyte.MaxValue) ThrowSByteOverflowException();
 0559            return (sbyte)value;
 560        }
 561
 562        [CLSCompliant(false)]
 563        public static sbyte ToSByte(byte value)
 564        {
 0565            if (value > sbyte.MaxValue) ThrowSByteOverflowException();
 0566            return (sbyte)value;
 567        }
 568
 569        [CLSCompliant(false)]
 570        public static sbyte ToSByte(short value)
 571        {
 0572            if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
 0573            return (sbyte)value;
 574        }
 575
 576        [CLSCompliant(false)]
 577        public static sbyte ToSByte(ushort value)
 578        {
 0579            if (value > sbyte.MaxValue) ThrowSByteOverflowException();
 0580            return (sbyte)value;
 581        }
 582
 583        [CLSCompliant(false)]
 584        public static sbyte ToSByte(int value)
 585        {
 0586            if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
 0587            return (sbyte)value;
 588        }
 589
 590        [CLSCompliant(false)]
 591        public static sbyte ToSByte(uint value)
 592        {
 0593            if (value > (uint)sbyte.MaxValue) ThrowSByteOverflowException();
 0594            return (sbyte)value;
 595        }
 596
 597        [CLSCompliant(false)]
 598        public static sbyte ToSByte(long value)
 599        {
 0600            if (value < sbyte.MinValue || value > sbyte.MaxValue) ThrowSByteOverflowException();
 0601            return (sbyte)value;
 602        }
 603
 604        [CLSCompliant(false)]
 605        public static sbyte ToSByte(ulong value)
 606        {
 0607            if (value > (ulong)sbyte.MaxValue) ThrowSByteOverflowException();
 0608            return (sbyte)value;
 609        }
 610
 611        [CLSCompliant(false)]
 612        public static sbyte ToSByte(float value)
 613        {
 0614            return ToSByte((double)value);
 615        }
 616
 617        [CLSCompliant(false)]
 618        public static sbyte ToSByte(double value)
 619        {
 0620            return ToSByte(ToInt32(value));
 621        }
 622
 623        [CLSCompliant(false)]
 624        public static sbyte ToSByte(decimal value)
 625        {
 0626            return decimal.ToSByte(decimal.Round(value, 0));
 627        }
 628
 629        [CLSCompliant(false)]
 630        public static sbyte ToSByte(string? value)
 631        {
 0632            if (value == null)
 0633                return 0;
 0634            return sbyte.Parse(value);
 635        }
 636
 637        [CLSCompliant(false)]
 638        public static sbyte ToSByte(string value, IFormatProvider? provider)
 639        {
 0640            return sbyte.Parse(value, provider);
 641        }
 642
 643        [CLSCompliant(false)]
 644        public static sbyte ToSByte(DateTime value)
 645        {
 0646            return ((IConvertible)value).ToSByte(null);
 647        }
 648
 649        // Disallowed conversions to SByte
 650        // public static sbyte ToSByte(TimeSpan value)
 651
 652        // Conversions to Byte
 653
 654        public static byte ToByte(object? value)
 655        {
 0656            return value == null ? (byte)0 : ((IConvertible)value).ToByte(null);
 657        }
 658
 659        public static byte ToByte(object? value, IFormatProvider? provider)
 660        {
 0661            return value == null ? (byte)0 : ((IConvertible)value).ToByte(provider);
 662        }
 663
 664        public static byte ToByte(bool value)
 665        {
 0666            return value ? (byte)bool.True : (byte)bool.False;
 667        }
 668
 669        public static byte ToByte(byte value)
 670        {
 0671            return value;
 672        }
 673
 674        public static byte ToByte(char value)
 675        {
 0676            if (value > byte.MaxValue) ThrowByteOverflowException();
 0677            return (byte)value;
 678        }
 679
 680        [CLSCompliant(false)]
 681        public static byte ToByte(sbyte value)
 682        {
 0683            if (value < 0) ThrowByteOverflowException();
 0684            return (byte)value;
 685        }
 686
 687        public static byte ToByte(short value)
 688        {
 0689            if ((uint)value > byte.MaxValue) ThrowByteOverflowException();
 0690            return (byte)value;
 691        }
 692
 693        [CLSCompliant(false)]
 694        public static byte ToByte(ushort value)
 695        {
 0696            if (value > byte.MaxValue) ThrowByteOverflowException();
 0697            return (byte)value;
 698        }
 699
 0700        public static byte ToByte(int value) => ToByte((uint)value);
 701
 702        [CLSCompliant(false)]
 703        public static byte ToByte(uint value)
 704        {
 0705            if (value > byte.MaxValue) ThrowByteOverflowException();
 0706            return (byte)value;
 707        }
 708
 0709        public static byte ToByte(long value) => ToByte((ulong)value);
 710
 711        [CLSCompliant(false)]
 712        public static byte ToByte(ulong value)
 713        {
 0714            if (value > byte.MaxValue) ThrowByteOverflowException();
 0715            return (byte)value;
 716        }
 717
 718        public static byte ToByte(float value)
 719        {
 0720            return ToByte((double)value);
 721        }
 722
 723        public static byte ToByte(double value)
 724        {
 0725            return ToByte(ToInt32(value));
 726        }
 727
 728        public static byte ToByte(decimal value)
 729        {
 0730            return decimal.ToByte(decimal.Round(value, 0));
 731        }
 732
 733        public static byte ToByte(string? value)
 734        {
 0735            if (value == null)
 0736                return 0;
 0737            return byte.Parse(value);
 738        }
 739
 740        public static byte ToByte(string? value, IFormatProvider? provider)
 741        {
 0742            if (value == null)
 0743                return 0;
 0744            return byte.Parse(value, provider);
 745        }
 746
 747        public static byte ToByte(DateTime value)
 748        {
 0749            return ((IConvertible)value).ToByte(null);
 750        }
 751
 752        // Disallowed conversions to Byte
 753        // public static byte ToByte(TimeSpan value)
 754
 755        // Conversions to Int16
 756
 757        public static short ToInt16(object? value)
 758        {
 0759            return value == null ? (short)0 : ((IConvertible)value).ToInt16(null);
 760        }
 761
 762        public static short ToInt16(object? value, IFormatProvider? provider)
 763        {
 0764            return value == null ? (short)0 : ((IConvertible)value).ToInt16(provider);
 765        }
 766
 767        public static short ToInt16(bool value)
 768        {
 0769            return value ? (short)bool.True : (short)bool.False;
 770        }
 771
 772        public static short ToInt16(char value)
 773        {
 0774            if (value > short.MaxValue) ThrowInt16OverflowException();
 0775            return (short)value;
 776        }
 777
 778        [CLSCompliant(false)]
 779        public static short ToInt16(sbyte value)
 780        {
 0781            return value;
 782        }
 783
 784        public static short ToInt16(byte value)
 785        {
 0786            return value;
 787        }
 788
 789        [CLSCompliant(false)]
 790        public static short ToInt16(ushort value)
 791        {
 0792            if (value > short.MaxValue) ThrowInt16OverflowException();
 0793            return (short)value;
 794        }
 795
 796        public static short ToInt16(int value)
 797        {
 0798            if (value < short.MinValue || value > short.MaxValue) ThrowInt16OverflowException();
 0799            return (short)value;
 800        }
 801
 802        [CLSCompliant(false)]
 803        public static short ToInt16(uint value)
 804        {
 0805            if (value > (uint)short.MaxValue) ThrowInt16OverflowException();
 0806            return (short)value;
 807        }
 808
 809        public static short ToInt16(short value)
 810        {
 0811            return value;
 812        }
 813
 814        public static short ToInt16(long value)
 815        {
 0816            if (value < short.MinValue || value > short.MaxValue) ThrowInt16OverflowException();
 0817            return (short)value;
 818        }
 819
 820        [CLSCompliant(false)]
 821        public static short ToInt16(ulong value)
 822        {
 0823            if (value > (ulong)short.MaxValue) ThrowInt16OverflowException();
 0824            return (short)value;
 825        }
 826
 827        public static short ToInt16(float value)
 828        {
 0829            return ToInt16((double)value);
 830        }
 831
 832        public static short ToInt16(double value)
 833        {
 0834            return ToInt16(ToInt32(value));
 835        }
 836
 837        public static short ToInt16(decimal value)
 838        {
 0839            return decimal.ToInt16(decimal.Round(value, 0));
 840        }
 841
 842        public static short ToInt16(string? value)
 843        {
 0844            if (value == null)
 0845                return 0;
 0846            return short.Parse(value);
 847        }
 848
 849        public static short ToInt16(string? value, IFormatProvider? provider)
 850        {
 0851            if (value == null)
 0852                return 0;
 0853            return short.Parse(value, provider);
 854        }
 855
 856        public static short ToInt16(DateTime value)
 857        {
 0858            return ((IConvertible)value).ToInt16(null);
 859        }
 860
 861        // Disallowed conversions to Int16
 862        // public static short ToInt16(TimeSpan value)
 863
 864        // Conversions to UInt16
 865
 866        [CLSCompliant(false)]
 867        public static ushort ToUInt16(object? value)
 868        {
 0869            return value == null ? (ushort)0 : ((IConvertible)value).ToUInt16(null);
 870        }
 871
 872        [CLSCompliant(false)]
 873        public static ushort ToUInt16(object? value, IFormatProvider? provider)
 874        {
 0875            return value == null ? (ushort)0 : ((IConvertible)value).ToUInt16(provider);
 876        }
 877
 878        [CLSCompliant(false)]
 879        public static ushort ToUInt16(bool value)
 880        {
 0881            return value ? (ushort)bool.True : (ushort)bool.False;
 882        }
 883
 884        [CLSCompliant(false)]
 885        public static ushort ToUInt16(char value)
 886        {
 0887            return value;
 888        }
 889
 890        [CLSCompliant(false)]
 891        public static ushort ToUInt16(sbyte value)
 892        {
 0893            if (value < 0) ThrowUInt16OverflowException();
 0894            return (ushort)value;
 895        }
 896
 897        [CLSCompliant(false)]
 898        public static ushort ToUInt16(byte value)
 899        {
 0900            return value;
 901        }
 902
 903        [CLSCompliant(false)]
 904        public static ushort ToUInt16(short value)
 905        {
 0906            if (value < 0) ThrowUInt16OverflowException();
 0907            return (ushort)value;
 908        }
 909
 910        [CLSCompliant(false)]
 0911        public static ushort ToUInt16(int value) => ToUInt16((uint)value);
 912
 913        [CLSCompliant(false)]
 914        public static ushort ToUInt16(ushort value)
 915        {
 0916            return value;
 917        }
 918
 919        [CLSCompliant(false)]
 920        public static ushort ToUInt16(uint value)
 921        {
 0922            if (value > ushort.MaxValue) ThrowUInt16OverflowException();
 0923            return (ushort)value;
 924        }
 925
 926        [CLSCompliant(false)]
 0927        public static ushort ToUInt16(long value) => ToUInt16((ulong)value);
 928
 929        [CLSCompliant(false)]
 930        public static ushort ToUInt16(ulong value)
 931        {
 0932            if (value > ushort.MaxValue) ThrowUInt16OverflowException();
 0933            return (ushort)value;
 934        }
 935
 936        [CLSCompliant(false)]
 937        public static ushort ToUInt16(float value)
 938        {
 0939            return ToUInt16((double)value);
 940        }
 941
 942        [CLSCompliant(false)]
 943        public static ushort ToUInt16(double value)
 944        {
 0945            return ToUInt16(ToInt32(value));
 946        }
 947
 948        [CLSCompliant(false)]
 949        public static ushort ToUInt16(decimal value)
 950        {
 0951            return decimal.ToUInt16(decimal.Round(value, 0));
 952        }
 953
 954        [CLSCompliant(false)]
 955        public static ushort ToUInt16(string? value)
 956        {
 0957            if (value == null)
 0958                return 0;
 0959            return ushort.Parse(value);
 960        }
 961
 962        [CLSCompliant(false)]
 963        public static ushort ToUInt16(string? value, IFormatProvider? provider)
 964        {
 0965            if (value == null)
 0966                return 0;
 0967            return ushort.Parse(value, provider);
 968        }
 969
 970        [CLSCompliant(false)]
 971        public static ushort ToUInt16(DateTime value)
 972        {
 0973            return ((IConvertible)value).ToUInt16(null);
 974        }
 975
 976        // Disallowed conversions to UInt16
 977        // public static ushort ToUInt16(TimeSpan value)
 978
 979        // Conversions to Int32
 980
 981        public static int ToInt32(object? value)
 982        {
 0983            return value == null ? 0 : ((IConvertible)value).ToInt32(null);
 984        }
 985
 986        public static int ToInt32(object? value, IFormatProvider? provider)
 987        {
 0988            return value == null ? 0 : ((IConvertible)value).ToInt32(provider);
 989        }
 990
 991        public static int ToInt32(bool value)
 992        {
 0993            return value ? bool.True : bool.False;
 994        }
 995
 996        public static int ToInt32(char value)
 997        {
 0998            return value;
 999        }
 1000
 1001        [CLSCompliant(false)]
 1002        public static int ToInt32(sbyte value)
 1003        {
 01004            return value;
 1005        }
 1006
 1007        public static int ToInt32(byte value)
 1008        {
 01009            return value;
 1010        }
 1011
 1012        public static int ToInt32(short value)
 1013        {
 01014            return value;
 1015        }
 1016
 1017        [CLSCompliant(false)]
 1018        public static int ToInt32(ushort value)
 1019        {
 01020            return value;
 1021        }
 1022
 1023        [CLSCompliant(false)]
 1024        public static int ToInt32(uint value)
 1025        {
 01026            if ((int)value < 0) ThrowInt32OverflowException();
 01027            return (int)value;
 1028        }
 1029
 1030        public static int ToInt32(int value)
 1031        {
 01032            return value;
 1033        }
 1034
 1035        public static int ToInt32(long value)
 1036        {
 01037            if (value < int.MinValue || value > int.MaxValue) ThrowInt32OverflowException();
 01038            return (int)value;
 1039        }
 1040
 1041        [CLSCompliant(false)]
 1042        public static int ToInt32(ulong value)
 1043        {
 01044            if (value > int.MaxValue) ThrowInt32OverflowException();
 01045            return (int)value;
 1046        }
 1047
 1048        public static int ToInt32(float value)
 1049        {
 01050            return ToInt32((double)value);
 1051        }
 1052
 1053        public static int ToInt32(double value)
 1054        {
 01055            if (value >= 0)
 1056            {
 01057                if (value < 2147483647.5)
 1058                {
 01059                    int result = (int)value;
 01060                    double dif = value - result;
 01061                    if (dif > 0.5 || dif == 0.5 && (result & 1) != 0) result++;
 01062                    return result;
 1063                }
 1064            }
 1065            else
 1066            {
 01067                if (value >= -2147483648.5)
 1068                {
 01069                    int result = (int)value;
 01070                    double dif = value - result;
 01071                    if (dif < -0.5 || dif == -0.5 && (result & 1) != 0) result--;
 01072                    return result;
 1073                }
 1074            }
 01075            throw new OverflowException(SR.Overflow_Int32);
 1076        }
 1077
 1078        public static int ToInt32(decimal value)
 1079        {
 01080            return decimal.ToInt32(decimal.Round(value, 0));
 1081        }
 1082
 1083        public static int ToInt32(string? value)
 1084        {
 01085            if (value == null)
 01086                return 0;
 01087            return int.Parse(value);
 1088        }
 1089
 1090        public static int ToInt32(string? value, IFormatProvider? provider)
 1091        {
 01092            if (value == null)
 01093                return 0;
 01094            return int.Parse(value, provider);
 1095        }
 1096
 1097        public static int ToInt32(DateTime value)
 1098        {
 01099            return ((IConvertible)value).ToInt32(null);
 1100        }
 1101
 1102        // Disallowed conversions to Int32
 1103        // public static int ToInt32(TimeSpan value)
 1104
 1105        // Conversions to UInt32
 1106
 1107        [CLSCompliant(false)]
 1108        public static uint ToUInt32(object? value)
 1109        {
 01110            return value == null ? 0 : ((IConvertible)value).ToUInt32(null);
 1111        }
 1112
 1113        [CLSCompliant(false)]
 1114        public static uint ToUInt32(object? value, IFormatProvider? provider)
 1115        {
 01116            return value == null ? 0 : ((IConvertible)value).ToUInt32(provider);
 1117        }
 1118
 1119        [CLSCompliant(false)]
 1120        public static uint ToUInt32(bool value)
 1121        {
 01122            return value ? (uint)bool.True : (uint)bool.False;
 1123        }
 1124
 1125        [CLSCompliant(false)]
 1126        public static uint ToUInt32(char value)
 1127        {
 01128            return value;
 1129        }
 1130
 1131        [CLSCompliant(false)]
 1132        public static uint ToUInt32(sbyte value)
 1133        {
 01134            if (value < 0) ThrowUInt32OverflowException();
 01135            return (uint)value;
 1136        }
 1137
 1138        [CLSCompliant(false)]
 1139        public static uint ToUInt32(byte value)
 1140        {
 01141            return value;
 1142        }
 1143
 1144        [CLSCompliant(false)]
 1145        public static uint ToUInt32(short value)
 1146        {
 01147            if (value < 0) ThrowUInt32OverflowException();
 01148            return (uint)value;
 1149        }
 1150
 1151        [CLSCompliant(false)]
 1152        public static uint ToUInt32(ushort value)
 1153        {
 01154            return value;
 1155        }
 1156
 1157        [CLSCompliant(false)]
 1158        public static uint ToUInt32(int value)
 1159        {
 01160            if (value < 0) ThrowUInt32OverflowException();
 01161            return (uint)value;
 1162        }
 1163
 1164        [CLSCompliant(false)]
 1165        public static uint ToUInt32(uint value)
 1166        {
 01167            return value;
 1168        }
 1169
 1170        [CLSCompliant(false)]
 01171        public static uint ToUInt32(long value) => ToUInt32((ulong)value);
 1172
 1173        [CLSCompliant(false)]
 1174        public static uint ToUInt32(ulong value)
 1175        {
 01176            if (value > uint.MaxValue) ThrowUInt32OverflowException();
 01177            return (uint)value;
 1178        }
 1179
 1180        [CLSCompliant(false)]
 1181        public static uint ToUInt32(float value)
 1182        {
 01183            return ToUInt32((double)value);
 1184        }
 1185
 1186        [CLSCompliant(false)]
 1187        public static uint ToUInt32(double value)
 1188        {
 01189            if (value >= -0.5 && value < 4294967295.5)
 1190            {
 01191                uint result = (uint)value;
 01192                double dif = value - result;
 01193                if (dif > 0.5 || dif == 0.5 && (result & 1) != 0) result++;
 01194                return result;
 1195            }
 01196            throw new OverflowException(SR.Overflow_UInt32);
 1197        }
 1198
 1199        [CLSCompliant(false)]
 1200        public static uint ToUInt32(decimal value)
 1201        {
 01202            return decimal.ToUInt32(decimal.Round(value, 0));
 1203        }
 1204
 1205        [CLSCompliant(false)]
 1206        public static uint ToUInt32(string? value)
 1207        {
 01208            if (value == null)
 01209                return 0;
 01210            return uint.Parse(value);
 1211        }
 1212
 1213        [CLSCompliant(false)]
 1214        public static uint ToUInt32(string? value, IFormatProvider? provider)
 1215        {
 01216            if (value == null)
 01217                return 0;
 01218            return uint.Parse(value, provider);
 1219        }
 1220
 1221        [CLSCompliant(false)]
 1222        public static uint ToUInt32(DateTime value)
 1223        {
 01224            return ((IConvertible)value).ToUInt32(null);
 1225        }
 1226
 1227        // Disallowed conversions to UInt32
 1228        // public static uint ToUInt32(TimeSpan value)
 1229
 1230        // Conversions to Int64
 1231
 1232        public static long ToInt64(object? value)
 1233        {
 01234            return value == null ? 0 : ((IConvertible)value).ToInt64(null);
 1235        }
 1236
 1237        public static long ToInt64(object? value, IFormatProvider? provider)
 1238        {
 01239            return value == null ? 0 : ((IConvertible)value).ToInt64(provider);
 1240        }
 1241
 1242        public static long ToInt64(bool value)
 1243        {
 01244            return value ? bool.True : bool.False;
 1245        }
 1246
 1247        public static long ToInt64(char value)
 1248        {
 01249            return value;
 1250        }
 1251
 1252        [CLSCompliant(false)]
 1253        public static long ToInt64(sbyte value)
 1254        {
 01255            return value;
 1256        }
 1257
 1258        public static long ToInt64(byte value)
 1259        {
 01260            return value;
 1261        }
 1262
 1263        public static long ToInt64(short value)
 1264        {
 01265            return value;
 1266        }
 1267
 1268        [CLSCompliant(false)]
 1269        public static long ToInt64(ushort value)
 1270        {
 01271            return value;
 1272        }
 1273
 1274        public static long ToInt64(int value)
 1275        {
 01276            return value;
 1277        }
 1278
 1279        [CLSCompliant(false)]
 1280        public static long ToInt64(uint value)
 1281        {
 01282            return value;
 1283        }
 1284
 1285        [CLSCompliant(false)]
 1286        public static long ToInt64(ulong value)
 1287        {
 01288            if ((long)value < 0) ThrowInt64OverflowException();
 01289            return (long)value;
 1290        }
 1291
 1292        public static long ToInt64(long value)
 1293        {
 01294            return value;
 1295        }
 1296
 1297        public static long ToInt64(float value)
 1298        {
 01299            return ToInt64((double)value);
 1300        }
 1301
 1302        public static long ToInt64(double value)
 1303        {
 01304            return checked((long)Math.Round(value));
 1305        }
 1306
 1307        public static long ToInt64(decimal value)
 1308        {
 01309            return decimal.ToInt64(decimal.Round(value, 0));
 1310        }
 1311
 1312        public static long ToInt64(string? value)
 1313        {
 01314            if (value == null)
 01315                return 0;
 01316            return long.Parse(value);
 1317        }
 1318
 1319        public static long ToInt64(string? value, IFormatProvider? provider)
 1320        {
 01321            if (value == null)
 01322                return 0;
 01323            return long.Parse(value, provider);
 1324        }
 1325
 1326        public static long ToInt64(DateTime value)
 1327        {
 01328            return ((IConvertible)value).ToInt64(null);
 1329        }
 1330
 1331        // Disallowed conversions to Int64
 1332        // public static long ToInt64(TimeSpan value)
 1333
 1334        // Conversions to UInt64
 1335
 1336        [CLSCompliant(false)]
 1337        public static ulong ToUInt64(object? value)
 1338        {
 01339            return value == null ? 0 : ((IConvertible)value).ToUInt64(null);
 1340        }
 1341
 1342        [CLSCompliant(false)]
 1343        public static ulong ToUInt64(object? value, IFormatProvider? provider)
 1344        {
 01345            return value == null ? 0 : ((IConvertible)value).ToUInt64(provider);
 1346        }
 1347
 1348        [CLSCompliant(false)]
 1349        public static ulong ToUInt64(bool value)
 1350        {
 01351            return value ? (ulong)bool.True : (ulong)bool.False;
 1352        }
 1353
 1354        [CLSCompliant(false)]
 1355        public static ulong ToUInt64(char value)
 1356        {
 01357            return value;
 1358        }
 1359
 1360        [CLSCompliant(false)]
 1361        public static ulong ToUInt64(sbyte value)
 1362        {
 01363            if (value < 0) ThrowUInt64OverflowException();
 01364            return (ulong)value;
 1365        }
 1366
 1367        [CLSCompliant(false)]
 1368        public static ulong ToUInt64(byte value)
 1369        {
 01370            return value;
 1371        }
 1372
 1373        [CLSCompliant(false)]
 1374        public static ulong ToUInt64(short value)
 1375        {
 01376            if (value < 0) ThrowUInt64OverflowException();
 01377            return (ulong)value;
 1378        }
 1379
 1380        [CLSCompliant(false)]
 1381        public static ulong ToUInt64(ushort value)
 1382        {
 01383            return value;
 1384        }
 1385
 1386        [CLSCompliant(false)]
 1387        public static ulong ToUInt64(int value)
 1388        {
 01389            if (value < 0) ThrowUInt64OverflowException();
 01390            return (ulong)value;
 1391        }
 1392
 1393        [CLSCompliant(false)]
 1394        public static ulong ToUInt64(uint value)
 1395        {
 01396            return value;
 1397        }
 1398
 1399        [CLSCompliant(false)]
 1400        public static ulong ToUInt64(long value)
 1401        {
 01402            if (value < 0) ThrowUInt64OverflowException();
 01403            return (ulong)value;
 1404        }
 1405
 1406        [CLSCompliant(false)]
 1407        public static ulong ToUInt64(ulong value)
 1408        {
 01409            return value;
 1410        }
 1411
 1412        [CLSCompliant(false)]
 1413        public static ulong ToUInt64(float value)
 1414        {
 01415            return ToUInt64((double)value);
 1416        }
 1417
 1418        [CLSCompliant(false)]
 1419        public static ulong ToUInt64(double value)
 1420        {
 01421            return checked((ulong)Math.Round(value));
 1422        }
 1423
 1424        [CLSCompliant(false)]
 1425        public static ulong ToUInt64(decimal value)
 1426        {
 01427            return decimal.ToUInt64(decimal.Round(value, 0));
 1428        }
 1429
 1430        [CLSCompliant(false)]
 1431        public static ulong ToUInt64(string? value)
 1432        {
 01433            if (value == null)
 01434                return 0;
 01435            return ulong.Parse(value);
 1436        }
 1437
 1438        [CLSCompliant(false)]
 1439        public static ulong ToUInt64(string? value, IFormatProvider? provider)
 1440        {
 01441            if (value == null)
 01442                return 0;
 01443            return ulong.Parse(value, provider);
 1444        }
 1445
 1446        [CLSCompliant(false)]
 1447        public static ulong ToUInt64(DateTime value)
 1448        {
 01449            return ((IConvertible)value).ToUInt64(null);
 1450        }
 1451
 1452        // Disallowed conversions to UInt64
 1453        // public static ulong ToUInt64(TimeSpan value)
 1454
 1455        // Conversions to Single
 1456
 1457        public static float ToSingle(object? value)
 1458        {
 01459            return value == null ? 0 : ((IConvertible)value).ToSingle(null);
 1460        }
 1461
 1462        public static float ToSingle(object? value, IFormatProvider? provider)
 1463        {
 01464            return value == null ? 0 : ((IConvertible)value).ToSingle(provider);
 1465        }
 1466
 1467        [CLSCompliant(false)]
 1468        public static float ToSingle(sbyte value)
 1469        {
 01470            return value;
 1471        }
 1472
 1473        public static float ToSingle(byte value)
 1474        {
 01475            return value;
 1476        }
 1477
 1478        public static float ToSingle(char value)
 1479        {
 01480            return ((IConvertible)value).ToSingle(null);
 1481        }
 1482
 1483        public static float ToSingle(short value)
 1484        {
 01485            return value;
 1486        }
 1487
 1488        [CLSCompliant(false)]
 1489        public static float ToSingle(ushort value)
 1490        {
 01491            return value;
 1492        }
 1493
 1494        public static float ToSingle(int value)
 1495        {
 01496            return value;
 1497        }
 1498
 1499        [CLSCompliant(false)]
 1500        public static float ToSingle(uint value)
 1501        {
 01502            return value;
 1503        }
 1504
 1505        public static float ToSingle(long value)
 1506        {
 01507            return value;
 1508        }
 1509
 1510        [CLSCompliant(false)]
 1511        public static float ToSingle(ulong value)
 1512        {
 01513            return value;
 1514        }
 1515
 1516        public static float ToSingle(float value)
 1517        {
 01518            return value;
 1519        }
 1520
 1521        public static float ToSingle(double value)
 1522        {
 01523            return (float)value;
 1524        }
 1525
 1526        public static float ToSingle(decimal value)
 1527        {
 01528            return (float)value;
 1529        }
 1530
 1531        public static float ToSingle(string? value)
 1532        {
 01533            if (value == null)
 01534                return 0;
 01535            return float.Parse(value);
 1536        }
 1537
 1538        public static float ToSingle(string? value, IFormatProvider? provider)
 1539        {
 01540            if (value == null)
 01541                return 0;
 01542            return float.Parse(value, provider);
 1543        }
 1544
 1545        public static float ToSingle(bool value)
 1546        {
 01547            return value ? bool.True : bool.False;
 1548        }
 1549
 1550        public static float ToSingle(DateTime value)
 1551        {
 01552            return ((IConvertible)value).ToSingle(null);
 1553        }
 1554
 1555        // Disallowed conversions to Single
 1556        // public static float ToSingle(TimeSpan value)
 1557
 1558        // Conversions to Double
 1559
 1560        public static double ToDouble(object? value)
 1561        {
 01562            return value == null ? 0 : ((IConvertible)value).ToDouble(null);
 1563        }
 1564
 1565        public static double ToDouble(object? value, IFormatProvider? provider)
 1566        {
 01567            return value == null ? 0 : ((IConvertible)value).ToDouble(provider);
 1568        }
 1569
 1570        [CLSCompliant(false)]
 1571        public static double ToDouble(sbyte value)
 1572        {
 01573            return value;
 1574        }
 1575
 1576        public static double ToDouble(byte value)
 1577        {
 01578            return value;
 1579        }
 1580
 1581        public static double ToDouble(short value)
 1582        {
 01583            return value;
 1584        }
 1585
 1586        public static double ToDouble(char value)
 1587        {
 01588            return ((IConvertible)value).ToDouble(null);
 1589        }
 1590
 1591        [CLSCompliant(false)]
 1592        public static double ToDouble(ushort value)
 1593        {
 01594            return value;
 1595        }
 1596
 1597        public static double ToDouble(int value)
 1598        {
 01599            return value;
 1600        }
 1601
 1602        [CLSCompliant(false)]
 1603        public static double ToDouble(uint value)
 1604        {
 01605            return value;
 1606        }
 1607
 1608        public static double ToDouble(long value)
 1609        {
 01610            return value;
 1611        }
 1612
 1613        [CLSCompliant(false)]
 1614        public static double ToDouble(ulong value)
 1615        {
 01616            return value;
 1617        }
 1618
 1619        public static double ToDouble(float value)
 1620        {
 01621            return value;
 1622        }
 1623
 1624        public static double ToDouble(double value)
 1625        {
 01626            return value;
 1627        }
 1628
 1629        public static double ToDouble(decimal value)
 1630        {
 01631            return (double)value;
 1632        }
 1633
 1634        public static double ToDouble(string? value)
 1635        {
 01636            if (value == null)
 01637                return 0;
 01638            return double.Parse(value);
 1639        }
 1640
 1641        public static double ToDouble(string? value, IFormatProvider? provider)
 1642        {
 01643            if (value == null)
 01644                return 0;
 01645            return double.Parse(value, provider);
 1646        }
 1647
 1648        public static double ToDouble(bool value)
 1649        {
 01650            return value ? bool.True : bool.False;
 1651        }
 1652
 1653        public static double ToDouble(DateTime value)
 1654        {
 01655            return ((IConvertible)value).ToDouble(null);
 1656        }
 1657
 1658        // Disallowed conversions to Double
 1659        // public static double ToDouble(TimeSpan value)
 1660
 1661        // Conversions to Decimal
 1662
 1663        public static decimal ToDecimal(object? value)
 1664        {
 01665            return value == null ? 0 : ((IConvertible)value).ToDecimal(null);
 1666        }
 1667
 1668        public static decimal ToDecimal(object? value, IFormatProvider? provider)
 1669        {
 01670            return value == null ? 0 : ((IConvertible)value).ToDecimal(provider);
 1671        }
 1672
 1673        [CLSCompliant(false)]
 1674        public static decimal ToDecimal(sbyte value)
 1675        {
 01676            return value;
 1677        }
 1678
 1679        public static decimal ToDecimal(byte value)
 1680        {
 01681            return value;
 1682        }
 1683
 1684        public static decimal ToDecimal(char value)
 1685        {
 01686            return ((IConvertible)value).ToDecimal(null);
 1687        }
 1688
 1689        public static decimal ToDecimal(short value)
 1690        {
 01691            return value;
 1692        }
 1693
 1694        [CLSCompliant(false)]
 1695        public static decimal ToDecimal(ushort value)
 1696        {
 01697            return value;
 1698        }
 1699
 1700        public static decimal ToDecimal(int value)
 1701        {
 01702            return value;
 1703        }
 1704
 1705        [CLSCompliant(false)]
 1706        public static decimal ToDecimal(uint value)
 1707        {
 01708            return value;
 1709        }
 1710
 1711        public static decimal ToDecimal(long value)
 1712        {
 01713            return value;
 1714        }
 1715
 1716        [CLSCompliant(false)]
 1717        public static decimal ToDecimal(ulong value)
 1718        {
 01719            return value;
 1720        }
 1721
 1722        public static decimal ToDecimal(float value)
 1723        {
 01724            return (decimal)value;
 1725        }
 1726
 1727        public static decimal ToDecimal(double value)
 1728        {
 01729            return (decimal)value;
 1730        }
 1731
 1732        public static decimal ToDecimal(string? value)
 1733        {
 01734            if (value == null)
 01735                return 0m;
 01736            return decimal.Parse(value);
 1737        }
 1738
 1739        public static decimal ToDecimal(string? value, IFormatProvider? provider)
 1740        {
 01741            if (value == null)
 01742                return 0m;
 01743            return decimal.Parse(value, provider);
 1744        }
 1745
 1746        public static decimal ToDecimal(decimal value)
 1747        {
 01748            return value;
 1749        }
 1750
 1751        public static decimal ToDecimal(bool value)
 1752        {
 01753            return value ? bool.True : bool.False;
 1754        }
 1755
 1756        public static decimal ToDecimal(DateTime value)
 1757        {
 01758            return ((IConvertible)value).ToDecimal(null);
 1759        }
 1760
 1761        // Disallowed conversions to Decimal
 1762        // public static decimal ToDecimal(TimeSpan value)
 1763
 1764        // Conversions to DateTime
 1765
 1766        public static DateTime ToDateTime(DateTime value)
 1767        {
 01768            return value;
 1769        }
 1770
 1771        public static DateTime ToDateTime(object? value)
 1772        {
 01773            return value == null ? DateTime.MinValue : ((IConvertible)value).ToDateTime(null);
 1774        }
 1775
 1776        public static DateTime ToDateTime(object? value, IFormatProvider? provider)
 1777        {
 01778            return value == null ? DateTime.MinValue : ((IConvertible)value).ToDateTime(provider);
 1779        }
 1780
 1781        public static DateTime ToDateTime(string? value)
 1782        {
 01783            if (value == null)
 01784                return new DateTime(0);
 01785            return DateTime.Parse(value);
 1786        }
 1787
 1788        public static DateTime ToDateTime(string? value, IFormatProvider? provider)
 1789        {
 01790            if (value == null)
 01791                return new DateTime(0);
 01792            return DateTime.Parse(value, provider);
 1793        }
 1794
 1795        [CLSCompliant(false)]
 1796        public static DateTime ToDateTime(sbyte value)
 1797        {
 01798            return ((IConvertible)value).ToDateTime(null);
 1799        }
 1800
 1801        public static DateTime ToDateTime(byte value)
 1802        {
 01803            return ((IConvertible)value).ToDateTime(null);
 1804        }
 1805
 1806        public static DateTime ToDateTime(short value)
 1807        {
 01808            return ((IConvertible)value).ToDateTime(null);
 1809        }
 1810
 1811        [CLSCompliant(false)]
 1812        public static DateTime ToDateTime(ushort value)
 1813        {
 01814            return ((IConvertible)value).ToDateTime(null);
 1815        }
 1816
 1817        public static DateTime ToDateTime(int value)
 1818        {
 01819            return ((IConvertible)value).ToDateTime(null);
 1820        }
 1821
 1822        [CLSCompliant(false)]
 1823        public static DateTime ToDateTime(uint value)
 1824        {
 01825            return ((IConvertible)value).ToDateTime(null);
 1826        }
 1827
 1828        public static DateTime ToDateTime(long value)
 1829        {
 01830            return ((IConvertible)value).ToDateTime(null);
 1831        }
 1832
 1833        [CLSCompliant(false)]
 1834        public static DateTime ToDateTime(ulong value)
 1835        {
 01836            return ((IConvertible)value).ToDateTime(null);
 1837        }
 1838
 1839        public static DateTime ToDateTime(bool value)
 1840        {
 01841            return ((IConvertible)value).ToDateTime(null);
 1842        }
 1843
 1844        public static DateTime ToDateTime(char value)
 1845        {
 01846            return ((IConvertible)value).ToDateTime(null);
 1847        }
 1848
 1849        public static DateTime ToDateTime(float value)
 1850        {
 01851            return ((IConvertible)value).ToDateTime(null);
 1852        }
 1853
 1854        public static DateTime ToDateTime(double value)
 1855        {
 01856            return ((IConvertible)value).ToDateTime(null);
 1857        }
 1858
 1859        public static DateTime ToDateTime(decimal value)
 1860        {
 01861            return ((IConvertible)value).ToDateTime(null);
 1862        }
 1863
 1864        // Disallowed conversions to DateTime
 1865        // public static DateTime ToDateTime(TimeSpan value)
 1866
 1867        // Conversions to String
 1868
 1869        public static string? ToString(object? value)
 1870        {
 01871            return ToString(value, null);
 1872        }
 1873
 1874        public static string? ToString(object? value, IFormatProvider? provider)
 1875        {
 01876            if (value is IConvertible ic)
 01877                return ic.ToString(provider);
 01878            if (value is IFormattable formattable)
 01879                return formattable.ToString(null, provider);
 01880            return value == null ? string.Empty : value.ToString();
 1881        }
 1882
 1883        public static string ToString(bool value)
 1884        {
 01885            return value.ToString();
 1886        }
 1887
 1888        public static string ToString(bool value, IFormatProvider? provider)
 1889        {
 01890            return value.ToString();
 1891        }
 1892
 1893        public static string ToString(char value)
 1894        {
 01895            return char.ToString(value);
 1896        }
 1897
 1898        public static string ToString(char value, IFormatProvider? provider)
 1899        {
 01900            return value.ToString();
 1901        }
 1902
 1903        [CLSCompliant(false)]
 1904        public static string ToString(sbyte value)
 1905        {
 01906            return value.ToString();
 1907        }
 1908
 1909        [CLSCompliant(false)]
 1910        public static string ToString(sbyte value, IFormatProvider? provider)
 1911        {
 01912            return value.ToString(provider);
 1913        }
 1914
 1915        public static string ToString(byte value)
 1916        {
 01917            return value.ToString();
 1918        }
 1919
 1920        public static string ToString(byte value, IFormatProvider? provider)
 1921        {
 01922            return value.ToString(provider);
 1923        }
 1924
 1925        public static string ToString(short value)
 1926        {
 01927            return value.ToString();
 1928        }
 1929
 1930        public static string ToString(short value, IFormatProvider? provider)
 1931        {
 01932            return value.ToString(provider);
 1933        }
 1934
 1935        [CLSCompliant(false)]
 1936        public static string ToString(ushort value)
 1937        {
 01938            return value.ToString();
 1939        }
 1940
 1941        [CLSCompliant(false)]
 1942        public static string ToString(ushort value, IFormatProvider? provider)
 1943        {
 01944            return value.ToString(provider);
 1945        }
 1946
 1947        public static string ToString(int value)
 1948        {
 01949            return value.ToString();
 1950        }
 1951
 1952        public static string ToString(int value, IFormatProvider? provider)
 1953        {
 01954            return value.ToString(provider);
 1955        }
 1956
 1957        [CLSCompliant(false)]
 1958        public static string ToString(uint value)
 1959        {
 01960            return value.ToString();
 1961        }
 1962
 1963        [CLSCompliant(false)]
 1964        public static string ToString(uint value, IFormatProvider? provider)
 1965        {
 01966            return value.ToString(provider);
 1967        }
 1968
 1969        public static string ToString(long value)
 1970        {
 01971            return value.ToString();
 1972        }
 1973
 1974        public static string ToString(long value, IFormatProvider? provider)
 1975        {
 01976            return value.ToString(provider);
 1977        }
 1978
 1979        [CLSCompliant(false)]
 1980        public static string ToString(ulong value)
 1981        {
 01982            return value.ToString();
 1983        }
 1984
 1985        [CLSCompliant(false)]
 1986        public static string ToString(ulong value, IFormatProvider? provider)
 1987        {
 01988            return value.ToString(provider);
 1989        }
 1990
 1991        public static string ToString(float value)
 1992        {
 01993            return value.ToString();
 1994        }
 1995
 1996        public static string ToString(float value, IFormatProvider? provider)
 1997        {
 01998            return value.ToString(provider);
 1999        }
 2000
 2001        public static string ToString(double value)
 2002        {
 02003            return value.ToString();
 2004        }
 2005
 2006        public static string ToString(double value, IFormatProvider? provider)
 2007        {
 02008            return value.ToString(provider);
 2009        }
 2010
 2011        public static string ToString(decimal value)
 2012        {
 02013            return value.ToString();
 2014        }
 2015
 2016        public static string ToString(decimal value, IFormatProvider? provider)
 2017        {
 02018            return value.ToString(provider);
 2019        }
 2020
 2021        public static string ToString(DateTime value)
 2022        {
 02023            return value.ToString();
 2024        }
 2025
 2026        public static string ToString(DateTime value, IFormatProvider? provider)
 2027        {
 02028            return value.ToString(provider);
 2029        }
 2030
 2031        [return: NotNullIfNotNull(nameof(value))]
 2032        public static string? ToString(string? value)
 2033        {
 02034            return value;
 2035        }
 2036
 2037        [return: NotNullIfNotNull(nameof(value))]
 2038        public static string? ToString(string? value, IFormatProvider? provider)
 2039        {
 02040            return value;
 2041        }
 2042
 2043        //
 2044        // Conversions which understand Base XXX numbers.
 2045        //
 2046        // Parses value in base base.  base can only
 2047        // be 2, 8, 10, or 16.  If base is 16, the number may be preceded
 2048        // by 0x or 0X; any other leading or trailing characters cause an error.
 2049        //
 2050        public static byte ToByte(string? value, int fromBase)
 2051        {
 02052            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2053            {
 02054                ThrowInvalidBase();
 2055            }
 2056
 02057            if (value == null)
 2058            {
 02059                return 0;
 2060            }
 2061
 02062            int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsign
 02063            if ((uint)r > byte.MaxValue)
 02064                ThrowByteOverflowException();
 02065            return (byte)r;
 2066        }
 2067
 2068        // Parses value in base fromBase.  fromBase can only
 2069        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2070        // by 0x or 0X; any other leading or trailing characters cause an error.
 2071        //
 2072        [CLSCompliant(false)]
 2073        public static sbyte ToSByte(string? value, int fromBase)
 2074        {
 02075            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2076            {
 02077                ThrowInvalidBase();
 2078            }
 2079
 02080            if (value == null)
 2081            {
 02082                return 0;
 2083            }
 2084
 02085            int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI1);
 02086            if (fromBase != 10 && r <= byte.MaxValue)
 02087                return (sbyte)r;
 2088
 02089            if (r < sbyte.MinValue || r > sbyte.MaxValue)
 02090                ThrowSByteOverflowException();
 02091            return (sbyte)r;
 2092        }
 2093
 2094        // Parses value in base fromBase.  fromBase can only
 2095        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2096        // by 0x or 0X; any other leading or trailing characters cause an error.
 2097        //
 2098        public static short ToInt16(string? value, int fromBase)
 2099        {
 02100            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2101            {
 02102                ThrowInvalidBase();
 2103            }
 2104
 02105            if (value == null)
 2106            {
 02107                return 0;
 2108            }
 2109
 02110            int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsI2);
 02111            if (fromBase != 10 && r <= ushort.MaxValue)
 02112                return (short)r;
 2113
 02114            if (r < short.MinValue || r > short.MaxValue)
 02115                ThrowInt16OverflowException();
 02116            return (short)r;
 2117        }
 2118
 2119        // Parses value in base fromBase.  fromBase can only
 2120        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2121        // by 0x or 0X; any other leading or trailing characters cause an error.
 2122        //
 2123        [CLSCompliant(false)]
 2124        public static ushort ToUInt16(string? value, int fromBase)
 2125        {
 02126            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2127            {
 02128                ThrowInvalidBase();
 2129            }
 2130
 02131            if (value == null)
 2132            {
 02133                return 0;
 2134            }
 2135
 02136            int r = ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight | ParseNumbers.TreatAsUnsign
 02137            if ((uint)r > ushort.MaxValue)
 02138                ThrowUInt16OverflowException();
 02139            return (ushort)r;
 2140        }
 2141
 2142        // Parses value in base fromBase.  fromBase can only
 2143        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2144        // by 0x or 0X; any other leading or trailing characters cause an error.
 2145        //
 2146        public static int ToInt32(string? value, int fromBase)
 2147        {
 02148            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2149            {
 02150                ThrowInvalidBase();
 2151            }
 02152            return value != null ?
 02153                ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
 02154                0;
 2155        }
 2156
 2157        // Parses value in base fromBase.  fromBase can only
 2158        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2159        // by 0x or 0X; any other leading or trailing characters cause an error.
 2160        //
 2161        [CLSCompliant(false)]
 2162        public static uint ToUInt32(string? value, int fromBase)
 2163        {
 02164            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2165            {
 02166                ThrowInvalidBase();
 2167            }
 02168            return value != null ?
 02169                (uint)ParseNumbers.StringToInt(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.IsT
 02170                0;
 2171        }
 2172
 2173        // Parses value in base fromBase.  fromBase can only
 2174        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2175        // by 0x or 0X; any other leading or trailing characters cause an error.
 2176        //
 2177        public static long ToInt64(string? value, int fromBase)
 2178        {
 02179            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2180            {
 02181                ThrowInvalidBase();
 2182            }
 02183            return value != null ?
 02184                ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.IsTight) :
 02185                0;
 2186        }
 2187
 2188        // Parses value in base fromBase.  fromBase can only
 2189        // be 2, 8, 10, or 16.  If fromBase is 16, the number may be preceded
 2190        // by 0x or 0X; any other leading or trailing characters cause an error.
 2191        //
 2192        [CLSCompliant(false)]
 2193        public static ulong ToUInt64(string? value, int fromBase)
 2194        {
 02195            if (fromBase != 2 && fromBase != 8 && fromBase != 10 && fromBase != 16)
 2196            {
 02197                ThrowInvalidBase();
 2198            }
 02199            return value != null ?
 02200                (ulong)ParseNumbers.StringToLong(value.AsSpan(), fromBase, ParseNumbers.TreatAsUnsigned | ParseNumbers.I
 02201                0;
 2202        }
 2203
 2204        // Convert the byte value to a string in base toBase
 2205        public static string ToString(byte value, int toBase) =>
 02206            ToString((int)value, toBase);
 2207
 2208        // Convert the Int16 value to a string in base toBase
 2209        public static string ToString(short value, int toBase)
 2210        {
 02211            string format = "d";
 2212
 2213            switch (toBase)
 2214            {
 2215                case 2:
 02216                    format = "b";
 02217                    break;
 2218
 2219                case 8:
 02220                    return ToOctalString((ushort)value);
 2221
 2222                case 10:
 2223                    break;
 2224
 2225                case 16:
 02226                    format = "x";
 02227                    break;
 2228
 2229                default:
 02230                    ThrowInvalidBase();
 2231                    break;
 2232            };
 2233
 02234            return value.ToString(format, CultureInfo.InvariantCulture);
 2235        }
 2236
 2237        // Convert the Int32 value to a string in base toBase
 2238        public static string ToString(int value, int toBase)
 2239        {
 02240            string format = "d";
 2241
 2242            switch (toBase)
 2243            {
 2244                case 2:
 02245                    format = "b";
 02246                    break;
 2247
 2248                case 8:
 02249                    return ToOctalString((uint)value);
 2250
 2251                case 10:
 2252                    break;
 2253
 2254                case 16:
 02255                    format = "x";
 02256                    break;
 2257
 2258                default:
 02259                    ThrowInvalidBase();
 2260                    break;
 2261            };
 2262
 02263            return value.ToString(format, CultureInfo.InvariantCulture);
 2264        }
 2265
 2266        // Convert the Int64 value to a string in base toBase
 2267        public static string ToString(long value, int toBase)
 2268        {
 02269            string format = "d";
 2270
 2271            switch (toBase)
 2272            {
 2273                case 2:
 02274                    format = "b";
 02275                    break;
 2276
 2277                case 8:
 02278                    return ToOctalString((ulong)value);
 2279
 2280                case 10:
 2281                    break;
 2282
 2283                case 16:
 02284                    format = "x";
 02285                    break;
 2286
 2287                default:
 02288                    ThrowInvalidBase();
 2289                    break;
 2290            };
 2291
 02292            return value.ToString(format, CultureInfo.InvariantCulture);
 2293        }
 2294
 02295        private static void ThrowInvalidBase() => throw new ArgumentException(SR.Arg_InvalidBase);
 2296
 2297        private static string ToOctalString(ulong value)
 2298        {
 02299            Span<char> chars = stackalloc char[22]; // max length of a ulong in octal
 2300
 02301            int i = chars.Length;
 2302            do
 2303            {
 02304                chars[--i] = (char)('0' + (value & 7));
 02305                value >>= 3;
 2306            }
 02307            while (value != 0);
 2308
 02309            return chars.Slice(i).ToString();
 2310        }
 2311
 2312        public static string ToBase64String(byte[] inArray)
 2313        {
 02314            ArgumentNullException.ThrowIfNull(inArray);
 2315
 02316            return Base64.EncodeToString(inArray);
 2317        }
 2318
 2319        public static string ToBase64String(byte[] inArray, Base64FormattingOptions options)
 2320        {
 02321            ArgumentNullException.ThrowIfNull(inArray);
 2322
 02323            return ToBase64String(new ReadOnlySpan<byte>(inArray), options);
 2324        }
 2325
 2326        public static string ToBase64String(byte[] inArray, int offset, int length)
 2327        {
 02328            return ToBase64String(inArray, offset, length, Base64FormattingOptions.None);
 2329        }
 2330
 2331        public static string ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options)
 2332        {
 02333            ArgumentNullException.ThrowIfNull(inArray);
 2334
 02335            ArgumentOutOfRangeException.ThrowIfNegative(length);
 02336            ArgumentOutOfRangeException.ThrowIfNegative(offset);
 02337            ArgumentOutOfRangeException.ThrowIfGreaterThan(offset, inArray.Length - length);
 2338
 02339            return ToBase64String(new ReadOnlySpan<byte>(inArray, offset, length), options);
 2340        }
 2341
 2342        public static string ToBase64String(ReadOnlySpan<byte> bytes, Base64FormattingOptions options = Base64Formatting
 2343        {
 238362344            if ((uint)options > (uint)Base64FormattingOptions.InsertLineBreaks)
 2345            {
 02346                throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
 2347            }
 2348
 238362349            if (bytes.Length == 0)
 2350            {
 02351                return string.Empty;
 2352            }
 2353
 238362354            bool insertLineBreaks = (options == Base64FormattingOptions.InsertLineBreaks);
 2355
 238362356            if (!insertLineBreaks)
 2357            {
 119182358                return Base64.EncodeToString(bytes);
 2359            }
 2360
 119182361            int outputLength = ToBase64_CalculateAndValidateOutputLength(bytes.Length, insertLineBreaks: true);
 2362
 119182363            return string.Create(outputLength, bytes, static (buffer, bytes) =>
 119182364            {
 119182365                int charsWritten = ConvertToBase64WithLineBreaks(buffer, bytes);
 119182366                Debug.Assert(buffer.Length == charsWritten, $"Expected {buffer.Length} == {charsWritten}");
 238362367            });
 2368        }
 2369
 2370        public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
 2371        {
 02372            return ToBase64CharArray(inArray, offsetIn, length, outArray, offsetOut, Base64FormattingOptions.None);
 2373        }
 2374
 2375        public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Ba
 2376        {
 238362377            ArgumentNullException.ThrowIfNull(inArray);
 238362378            ArgumentNullException.ThrowIfNull(outArray);
 2379
 238362380            ArgumentOutOfRangeException.ThrowIfNegative(length);
 238362381            ArgumentOutOfRangeException.ThrowIfNegative(offsetIn);
 238362382            ArgumentOutOfRangeException.ThrowIfNegative(offsetOut);
 238362383            if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks)
 02384                throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
 2385
 238362386            int inArrayLength = inArray.Length;
 2387
 238362388            ArgumentOutOfRangeException.ThrowIfGreaterThan(offsetIn, inArrayLength - length);
 2389
 238362390            if (length == 0)
 02391                return 0;
 2392
 2393            // This is the maximally required length that must be available in the char array
 238362394            int outArrayLength = outArray.Length;
 2395
 2396            // Length of the char buffer required
 238362397            bool insertLineBreaks = options == Base64FormattingOptions.InsertLineBreaks;
 238362398            int charLengthRequired = ToBase64_CalculateAndValidateOutputLength(length, insertLineBreaks);
 2399
 238362400            ArgumentOutOfRangeException.ThrowIfGreaterThan(offsetOut, outArrayLength - charLengthRequired);
 2401
 238362402            if (!insertLineBreaks)
 2403            {
 119182404                int charsWritten = Base64.EncodeToChars(new ReadOnlySpan<byte>(inArray, offsetIn, length), outArray.AsSp
 119182405                Debug.Assert(charsWritten == charLengthRequired);
 2406            }
 2407            else
 2408            {
 119182409                int converted = ConvertToBase64WithLineBreaks(outArray.AsSpan(offsetOut), new ReadOnlySpan<byte>(inArray
 119182410                Debug.Assert(converted == charLengthRequired);
 2411            }
 2412
 238362413            return charLengthRequired;
 2414        }
 2415
 2416        public static bool TryToBase64Chars(ReadOnlySpan<byte> bytes, Span<char> chars, out int charsWritten, Base64Form
 2417        {
 02418            if ((uint)options > (uint)Base64FormattingOptions.InsertLineBreaks)
 2419            {
 02420                throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)options), nameof(options));
 2421            }
 2422
 02423            if (bytes.Length == 0)
 2424            {
 02425                charsWritten = 0;
 02426                return true;
 2427            }
 2428
 02429            bool insertLineBreaks = options == Base64FormattingOptions.InsertLineBreaks;
 2430
 02431            int charLengthRequired = ToBase64_CalculateAndValidateOutputLength(bytes.Length, insertLineBreaks);
 02432            if (charLengthRequired > chars.Length)
 2433            {
 02434                charsWritten = 0;
 02435                return false;
 2436            }
 2437
 02438            if (!insertLineBreaks)
 2439            {
 02440                int written = Base64.EncodeToChars(bytes, chars);
 02441                Debug.Assert(written == charLengthRequired);
 2442            }
 2443            else
 2444            {
 02445                int converted = ConvertToBase64WithLineBreaks(chars, bytes);
 02446                Debug.Assert(converted == charLengthRequired);
 2447            }
 2448
 02449            charsWritten = charLengthRequired;
 02450            return true;
 2451        }
 2452
 2453        private static int ConvertToBase64WithLineBreaks(Span<char> destination, ReadOnlySpan<byte> source)
 2454        {
 238362455            Debug.Assert(destination.Length >= ToBase64_CalculateAndValidateOutputLength(source.Length, insertLineBreaks
 2456
 238362457            int writeOffset = 0;
 2458
 2145402459            while (true)
 2460            {
 2383762461                int chunkSize = Math.Min(source.Length, Base64LineBreakPosition / 4 * 3); // 76 base64 chars == 57 bytes
 2462
 2383762463                OperationStatus status = Base64.EncodeToChars(source.Slice(0, chunkSize), destination.Slice(writeOffset)
 2383762464                Debug.Assert(status == OperationStatus.Done && bytesConsumed == chunkSize);
 2465
 2383762466                source = source.Slice(chunkSize);
 2383762467                writeOffset += charsWritten;
 2468
 2383762469                if (source.IsEmpty)
 2470                {
 2471                    break;
 2472                }
 2473
 2145402474                destination[writeOffset++] = '\r';
 2145402475                destination[writeOffset++] = '\n';
 2476            }
 2477
 238362478            return writeOffset;
 2479        }
 2480
 2481        private static int ToBase64_CalculateAndValidateOutputLength(int inputLength, bool insertLineBreaks)
 2482        {
 2483            // the base length - we want integer division here, at most 4 more chars for the remainder
 595902484            uint outlen = ((uint)inputLength + 2) / 3 * 4;
 2485
 595902486            if (outlen == 0)
 02487                return 0;
 2488
 595902489            if (insertLineBreaks)
 2490            {
 476722491                (uint newLines, uint remainder) = Math.DivRem(outlen, Base64LineBreakPosition);
 476722492                if (remainder == 0)
 2493                {
 18322494                    --newLines;
 2495                }
 476722496                outlen += newLines * 2;              // the number of line break chars we'll add, "\r\n"
 2497            }
 2498
 2499            // If we overflow an int then we cannot allocate enough
 2500            // memory to output the value so throw
 595902501            if (outlen > int.MaxValue)
 02502                throw new OutOfMemoryException();
 2503
 595902504            return (int)outlen;
 2505        }
 2506
 2507        /// <summary>
 2508        /// Converts the specified string, which encodes binary data as Base64 digits, to the equivalent byte array.
 2509        /// </summary>
 2510        /// <param name="s">The string to convert</param>
 2511        /// <returns>The array of bytes represented by the specified Base64 string.</returns>
 2512        public static byte[] FromBase64String(string s)
 2513        {
 2514            // "s" is an unfortunate parameter name, but we need to keep it for backward compat.
 2515
 238362516            if (s == null)
 2517            {
 02518                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
 2519            }
 2520
 238362521            return Base64.DecodeFromChars(s);
 2522        }
 2523
 2524        public static bool TryFromBase64String(string s, Span<byte> bytes, out int bytesWritten)
 2525        {
 02526            if (s == null)
 2527            {
 02528                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
 2529            }
 2530
 02531            return TryFromBase64Chars(s.AsSpan(), bytes, out bytesWritten);
 2532        }
 2533
 2534        public static bool TryFromBase64Chars(ReadOnlySpan<char> chars, Span<byte> bytes, out int bytesWritten)
 2535        {
 02536            OperationStatus status = Base64.DecodeFromChars(chars, bytes, out _, out bytesWritten);
 02537            if (status == OperationStatus.Done)
 2538            {
 02539                return true;
 2540            }
 2541
 02542            bytesWritten = 0;
 02543            return false;
 2544        }
 2545
 2546        /// <summary>
 2547        /// Converts the specified range of a Char array, which encodes binary data as Base64 digits, to the equivalent 
 2548        /// </summary>
 2549        /// <param name="inArray">Chars representing Base64 encoding characters</param>
 2550        /// <param name="offset">A position within the input array.</param>
 2551        /// <param name="length">Number of element to convert.</param>
 2552        /// <returns>The array of bytes represented by the specified Base64 encoding characters.</returns>
 2553        public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
 2554        {
 238362555            ArgumentNullException.ThrowIfNull(inArray);
 238362556            ArgumentOutOfRangeException.ThrowIfNegative(length);
 238362557            ArgumentOutOfRangeException.ThrowIfNegative(offset);
 238362558            ArgumentOutOfRangeException.ThrowIfGreaterThan(offset, inArray.Length - length);
 2559
 238362560            return Base64.DecodeFromChars(new ReadOnlySpan<char>(inArray, offset, length));
 2561        }
 2562
 2563        /// <summary>Converts the specified string, which encodes binary data as hex characters, to an equivalent 8-bit 
 2564        /// <param name="s">The string to convert.</param>
 2565        /// <returns>An array of 8-bit unsigned integers that is equivalent to <paramref name="s"/>.</returns>
 2566        /// <exception cref="ArgumentNullException"><paramref name="s"/> is <code>null</code>.</exception>
 2567        /// <exception cref="FormatException">The length of <paramref name="s"/>, is not zero or a multiple of 2.</excep
 2568        /// <exception cref="FormatException">The format of <paramref name="s"/> is invalid. <paramref name="s"/> contai
 2569        public static byte[] FromHexString(string s)
 2570        {
 02571            if (s is null)
 2572            {
 02573                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
 2574            }
 02575            return FromHexString(s.AsSpan());
 2576        }
 2577
 2578        /// <summary>Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned int
 2579        /// <param name="chars">The span to convert.</param>
 2580        /// <returns>An array of 8-bit unsigned integers that is equivalent to <paramref name="chars"/>.</returns>
 2581        /// <exception cref="FormatException">The length of <paramref name="chars"/>, is not zero or a multiple of 2.</e
 2582        /// <exception cref="FormatException">The format of <paramref name="chars"/> is invalid. <paramref name="chars"/
 2583        public static byte[] FromHexString(ReadOnlySpan<char> chars)
 2584        {
 02585            if (chars.Length == 0)
 2586            {
 02587                return [];
 2588            }
 2589
 02590            if (!int.IsEvenInteger(chars.Length))
 2591            {
 02592                ThrowHelper.ThrowFormatException_BadHexLength();
 2593            }
 2594
 02595            byte[] result = GC.AllocateUninitializedArray<byte>(chars.Length / 2);
 2596
 02597            if (!HexConverter.TryDecodeFromUtf16(chars, result, out _))
 2598            {
 02599                ThrowHelper.ThrowFormatException_BadHexChar();
 2600            }
 02601            return result;
 2602        }
 2603
 2604        /// <summary>Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned int
 2605        /// <param name="utf8Source">The UTF-8 span to convert.</param>
 2606        /// <returns>An array of 8-bit unsigned integers that is equivalent to <paramref name="utf8Source"/>.</returns>
 2607        /// <exception cref="FormatException">The length of <paramref name="utf8Source"/>, is not zero or a multiple of 
 2608        /// <exception cref="FormatException">The format of <paramref name="utf8Source"/> is invalid. <paramref name="ut
 2609        public static byte[] FromHexString(ReadOnlySpan<byte> utf8Source)
 2610        {
 02611            if (utf8Source.Length == 0)
 2612            {
 02613                return [];
 2614            }
 2615
 02616            if (!int.IsEvenInteger(utf8Source.Length))
 2617            {
 02618                ThrowHelper.ThrowFormatException_BadHexLength();
 2619            }
 2620
 02621            byte[] result = GC.AllocateUninitializedArray<byte>(utf8Source.Length / 2);
 2622
 02623            if (!HexConverter.TryDecodeFromUtf8(utf8Source, result, out _))
 2624            {
 02625                ThrowHelper.ThrowFormatException_BadHexChar();
 2626            }
 02627            return result;
 2628        }
 2629
 2630        /// <summary>Converts the string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned i
 2631        /// <param name="source">The string to convert.</param>
 2632        /// <param name="destination">
 2633        /// The span in which to write the converted 8-bit unsigned integers. When this method returns value different t
 2634        /// either the span remains unmodified or contains an incomplete conversion of <paramref name="source"/>,
 2635        /// up to the last valid character.
 2636        /// </param>
 2637        /// <param name="bytesWritten">When this method returns, contains the number of bytes that were written to <para
 2638        /// <param name="charsConsumed">When this method returns, contains the number of characters that were consumed f
 2639        /// <returns>An <see cref="OperationStatus"/> describing the result of the operation.</returns>
 2640        /// <exception cref="ArgumentNullException">Passed string <paramref name="source"/> is null.</exception>
 2641        public static OperationStatus FromHexString(string source, Span<byte> destination, out int charsConsumed, out in
 2642        {
 02643            ArgumentNullException.ThrowIfNull(source);
 02644            return FromHexString(source.AsSpan(), destination, out charsConsumed, out bytesWritten);
 2645        }
 2646
 2647        /// <summary>Converts the span of chars, which encodes binary data as hex characters, to an equivalent 8-bit uns
 2648        /// <param name="source">The span to convert.</param>
 2649        /// <param name="destination">
 2650        /// The span in which to write the converted 8-bit unsigned integers. When this method returns value different t
 2651        /// either the span remains unmodified or contains an incomplete conversion of <paramref name="source"/>,
 2652        /// up to the last valid character.
 2653        /// </param>
 2654        /// <param name="bytesWritten">When this method returns, contains the number of bytes that were written to <para
 2655        /// <param name="charsConsumed">When this method returns, contains the number of characters that were consumed f
 2656        /// <returns>An <see cref="OperationStatus"/> describing the result of the operation.</returns>
 2657        public static OperationStatus FromHexString(ReadOnlySpan<char> source, Span<byte> destination, out int charsCons
 2658        {
 02659            (int quotient, int remainder) = Math.DivRem(source.Length, 2);
 2660
 02661            if (quotient == 0)
 2662            {
 02663                charsConsumed = 0;
 02664                bytesWritten = 0;
 2665
 02666                return (remainder == 1) ? OperationStatus.NeedMoreData : OperationStatus.Done;
 2667            }
 2668
 2669            OperationStatus result;
 2670
 02671            if (destination.Length < quotient)
 2672            {
 02673                source = source.Slice(0, destination.Length * 2);
 02674                quotient = destination.Length;
 02675                result = OperationStatus.DestinationTooSmall;
 2676            }
 2677            else
 2678            {
 02679                if (remainder == 1)
 2680                {
 02681                    source = source.Slice(0, source.Length - 1);
 02682                    result = OperationStatus.NeedMoreData;
 2683                }
 2684                else
 2685                {
 02686                    result = OperationStatus.Done;
 2687                }
 2688
 02689                destination = destination.Slice(0, quotient);
 2690            }
 2691
 02692            if (!HexConverter.TryDecodeFromUtf16(source, destination, out charsConsumed))
 2693            {
 02694                bytesWritten = charsConsumed / 2;
 02695                return OperationStatus.InvalidData;
 2696            }
 2697
 02698            bytesWritten = quotient;
 02699            charsConsumed = source.Length;
 02700            return result;
 2701        }
 2702
 2703        /// <summary>Converts the span of UTF-8 chars, which encodes binary data as hex characters, to an equivalent 8-b
 2704        /// <param name="utf8Source">The span to convert.</param>
 2705        /// <param name="destination">
 2706        /// The span in which to write the converted 8-bit unsigned integers. When this method returns value different t
 2707        /// either the span remains unmodified or contains an incomplete conversion of <paramref name="utf8Source"/>,
 2708        /// up to the last valid character.
 2709        /// </param>
 2710        /// <param name="bytesWritten">When this method returns, contains the number of bytes that were written to <para
 2711        /// <param name="bytesConsumed">When this method returns, contains the number of bytes that were consumed from <
 2712        /// <returns>An <see cref="OperationStatus"/> describing the result of the operation.</returns>
 2713        public static OperationStatus FromHexString(ReadOnlySpan<byte> utf8Source, Span<byte> destination, out int bytes
 2714        {
 02715            (int quotient, int remainder) = Math.DivRem(utf8Source.Length, 2);
 2716
 02717            if (quotient == 0)
 2718            {
 02719                bytesConsumed = 0;
 02720                bytesWritten = 0;
 2721
 02722                return (remainder == 1) ? OperationStatus.NeedMoreData : OperationStatus.Done;
 2723            }
 2724
 2725            OperationStatus result;
 2726
 02727            if (destination.Length < quotient)
 2728            {
 02729                utf8Source = utf8Source.Slice(0, destination.Length * 2);
 02730                quotient = destination.Length;
 02731                result = OperationStatus.DestinationTooSmall;
 2732            }
 2733            else
 2734            {
 02735                if (remainder == 1)
 2736                {
 02737                    utf8Source = utf8Source.Slice(0, utf8Source.Length - 1);
 02738                    result = OperationStatus.NeedMoreData;
 2739                }
 2740                else
 2741                {
 02742                    result = OperationStatus.Done;
 2743                }
 2744
 02745                destination = destination.Slice(0, quotient);
 2746            }
 2747
 02748            if (!HexConverter.TryDecodeFromUtf8(utf8Source, destination, out bytesConsumed))
 2749            {
 02750                bytesWritten = bytesConsumed / 2;
 02751                return OperationStatus.InvalidData;
 2752            }
 2753
 02754            bytesWritten = quotient;
 02755            bytesConsumed = utf8Source.Length;
 02756            return result;
 2757        }
 2758
 2759        /// <summary>Converts an array of 8-bit unsigned integers to its equivalent string representation that is encode
 2760        /// <param name="inArray">An array of 8-bit unsigned integers.</param>
 2761        /// <returns>The string representation in hex of the elements in <paramref name="inArray"/>.</returns>
 2762        /// <exception cref="ArgumentNullException"><paramref name="inArray"/> is <code>null</code>.</exception>
 2763        /// <exception cref="ArgumentOutOfRangeException"><paramref name="inArray"/> is too large to be encoded.</except
 2764        public static string ToHexString(byte[] inArray)
 2765        {
 02766            ArgumentNullException.ThrowIfNull(inArray);
 02767            return ToHexString(new ReadOnlySpan<byte>(inArray));
 2768        }
 2769
 2770        /// <summary>
 2771        /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is enc
 2772        /// Parameters specify the subset as an offset in the input array and the number of elements in the array to con
 2773        /// </summary>
 2774        /// <param name="inArray">An array of 8-bit unsigned integers.</param>
 2775        /// <param name="offset">An offset in <paramref name="inArray"/>.</param>
 2776        /// <param name="length">The number of elements of <paramref name="inArray"/> to convert.</param>
 2777        /// <returns>The string representation in hex of <paramref name="length"/> elements of <paramref name="inArray"/
 2778        /// <exception cref="ArgumentNullException"><paramref name="inArray"/> is <code>null</code>.</exception>
 2779        /// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="length"/> is nega
 2780        /// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> plus <paramref name="length"/> is gr
 2781        /// <exception cref="ArgumentOutOfRangeException"><paramref name="inArray"/> is too large to be encoded.</except
 2782        public static string ToHexString(byte[] inArray, int offset, int length)
 2783        {
 02784            ArgumentNullException.ThrowIfNull(inArray);
 2785
 02786            ArgumentOutOfRangeException.ThrowIfNegative(length);
 02787            ArgumentOutOfRangeException.ThrowIfNegative(offset);
 02788            ArgumentOutOfRangeException.ThrowIfGreaterThan(offset, inArray.Length - length);
 2789
 02790            return ToHexString(new ReadOnlySpan<byte>(inArray, offset, length));
 2791        }
 2792
 2793        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded 
 2794        /// <param name="bytes">A span of 8-bit unsigned integers.</param>
 2795        /// <returns>The string representation in hex of the elements in <paramref name="bytes"/>.</returns>
 2796        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bytes"/> is too large to be encoded.</exceptio
 2797        public static string ToHexString(ReadOnlySpan<byte> bytes)
 2798        {
 02799            if (bytes.Length == 0)
 2800            {
 02801                return string.Empty;
 2802            }
 02803            ArgumentOutOfRangeException.ThrowIfGreaterThan(bytes.Length, int.MaxValue / 2, nameof(bytes));
 2804
 02805            return HexConverter.ToString(bytes, HexConverter.Casing.Upper);
 2806        }
 2807
 2808        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent span representation that is encoded wi
 2809        /// <param name="source">A span of 8-bit unsigned integers.</param>
 2810        /// <param name="destination">The span representation in hex of the elements in <paramref name="source"/>.</para
 2811        /// <param name="charsWritten">When this method returns, contains the number of chars that were written in <para
 2812        /// <returns>true if the conversion was successful; otherwise, false.</returns>
 2813        public static bool TryToHexString(ReadOnlySpan<byte> source, Span<char> destination, out int charsWritten)
 2814        {
 02815            if (source.Length == 0)
 2816            {
 02817                charsWritten = 0;
 02818                return true;
 2819            }
 02820            else if ((source.Length > (int.MaxValue / 2)) || (destination.Length < (source.Length * 2)))
 2821            {
 02822                charsWritten = 0;
 02823                return false;
 2824            }
 2825
 02826            HexConverter.EncodeToUtf16(source, destination);
 02827            charsWritten = source.Length * 2;
 02828            return true;
 2829        }
 2830
 2831        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent UTF-8 span representation that is enco
 2832        /// <param name="source">A span of 8-bit unsigned integers.</param>
 2833        /// <param name="utf8Destination">The UTF-8 span representation in hex of the elements in <paramref name="source
 2834        /// <param name="bytesWritten">When this method returns, contains the number of bytes that were written in <para
 2835        /// <returns>true if the conversion was successful; otherwise, false.</returns>
 2836        public static bool TryToHexString(ReadOnlySpan<byte> source, Span<byte> utf8Destination, out int bytesWritten)
 2837        {
 02838            if (source.Length == 0)
 2839            {
 02840                bytesWritten = 0;
 02841                return true;
 2842            }
 02843            else if ((source.Length > (int.MaxValue / 2)) || (utf8Destination.Length < (source.Length * 2)))
 2844            {
 02845                bytesWritten = 0;
 02846                return false;
 2847            }
 2848
 02849            HexConverter.EncodeToUtf8(source, utf8Destination);
 02850            bytesWritten = source.Length * 2;
 02851            return true;
 2852        }
 2853
 2854        /// <summary>Converts an array of 8-bit unsigned integers to its equivalent string representation that is encode
 2855        /// <param name="inArray">An array of 8-bit unsigned integers.</param>
 2856        /// <returns>The string representation in hex of the elements in <paramref name="inArray"/>.</returns>
 2857        /// <exception cref="ArgumentNullException"><paramref name="inArray"/> is <code>null</code>.</exception>
 2858        /// <exception cref="ArgumentOutOfRangeException"><paramref name="inArray"/> is too large to be encoded.</except
 2859        public static string ToHexStringLower(byte[] inArray)
 2860        {
 02861            ArgumentNullException.ThrowIfNull(inArray);
 02862            return ToHexStringLower(new ReadOnlySpan<byte>(inArray));
 2863        }
 2864
 2865        /// <summary>
 2866        /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is enc
 2867        /// Parameters specify the subset as an offset in the input array and the number of elements in the array to con
 2868        /// </summary>
 2869        /// <param name="inArray">An array of 8-bit unsigned integers.</param>
 2870        /// <param name="offset">An offset in <paramref name="inArray"/>.</param>
 2871        /// <param name="length">The number of elements of <paramref name="inArray"/> to convert.</param>
 2872        /// <returns>The string representation in hex of <paramref name="length"/> elements of <paramref name="inArray"/
 2873        /// <exception cref="ArgumentNullException"><paramref name="inArray"/> is <code>null</code>.</exception>
 2874        /// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="length"/> is nega
 2875        /// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> plus <paramref name="length"/> is gr
 2876        /// <exception cref="ArgumentOutOfRangeException"><paramref name="inArray"/> is too large to be encoded.</except
 2877        public static string ToHexStringLower(byte[] inArray, int offset, int length)
 2878        {
 02879            ArgumentNullException.ThrowIfNull(inArray);
 2880
 02881            ArgumentOutOfRangeException.ThrowIfNegative(length);
 02882            ArgumentOutOfRangeException.ThrowIfNegative(offset);
 02883            ArgumentOutOfRangeException.ThrowIfGreaterThan(offset, inArray.Length - length);
 2884
 02885            return ToHexStringLower(new ReadOnlySpan<byte>(inArray, offset, length));
 2886        }
 2887
 2888        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded 
 2889        /// <param name="bytes">A span of 8-bit unsigned integers.</param>
 2890        /// <returns>The string representation in hex of the elements in <paramref name="bytes"/>.</returns>
 2891        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bytes"/> is too large to be encoded.</exceptio
 2892        public static string ToHexStringLower(ReadOnlySpan<byte> bytes)
 2893        {
 02894            if (bytes.Length == 0)
 2895            {
 02896                return string.Empty;
 2897            }
 02898            ArgumentOutOfRangeException.ThrowIfGreaterThan(bytes.Length, int.MaxValue / 2, nameof(bytes));
 2899
 02900            return HexConverter.ToString(bytes, HexConverter.Casing.Lower);
 2901        }
 2902
 2903        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent span representation that is encoded wi
 2904        /// <param name="source">A span of 8-bit unsigned integers.</param>
 2905        /// <param name="destination">The span representation in hex of the elements in <paramref name="source"/>.</para
 2906        /// <param name="charsWritten">When this method returns, contains the number of chars that were written in <para
 2907        /// <returns>true if the conversion was successful; otherwise, false.</returns>
 2908        public static bool TryToHexStringLower(ReadOnlySpan<byte> source, Span<char> destination, out int charsWritten)
 2909        {
 02910            if (source.Length == 0)
 2911            {
 02912                charsWritten = 0;
 02913                return true;
 2914            }
 02915            else if ((source.Length > (int.MaxValue / 2)) || (destination.Length < (source.Length * 2)))
 2916            {
 02917                charsWritten = 0;
 02918                return false;
 2919            }
 2920
 02921            HexConverter.EncodeToUtf16(source, destination, HexConverter.Casing.Lower);
 02922            charsWritten = source.Length * 2;
 02923            return true;
 2924        }
 2925
 2926        /// <summary>Converts a span of 8-bit unsigned integers to its equivalent UTF-8 span representation that is enco
 2927        /// <param name="source">A span of 8-bit unsigned integers.</param>
 2928        /// <param name="utf8Destination">The UTF-8 span representation in hex of the elements in <paramref name="source
 2929        /// <param name="bytesWritten">When this method returns, contains the number of bytes that were written in <para
 2930        /// <returns>true if the conversion was successful; otherwise, false.</returns>
 2931        public static bool TryToHexStringLower(ReadOnlySpan<byte> source, Span<byte> utf8Destination, out int bytesWritt
 2932        {
 02933            if (source.Length == 0)
 2934            {
 02935                bytesWritten = 0;
 02936                return true;
 2937            }
 02938            else if ((source.Length > (int.MaxValue / 2)) || (utf8Destination.Length < (source.Length * 2)))
 2939            {
 02940                bytesWritten = 0;
 02941                return false;
 2942            }
 2943
 02944            HexConverter.EncodeToUtf8(source, utf8Destination, HexConverter.Casing.Lower);
 02945            bytesWritten = source.Length * 2;
 02946            return true;
 2947        }
 2948    }
 2949}

Methods/Properties

.cctor()
GetTypeCode(System.Object)
IsDBNull(System.Object)
ChangeType(System.Object,System.TypeCode)
ChangeType(System.Object,System.TypeCode,System.IFormatProvider)
DefaultToType(System.IConvertible,System.Type,System.IFormatProvider)
ChangeType(System.Object,System.Type)
ChangeType(System.Object,System.Type,System.IFormatProvider)
ThrowCharOverflowException()
ThrowByteOverflowException()
ThrowSByteOverflowException()
ThrowInt16OverflowException()
ThrowUInt16OverflowException()
ThrowInt32OverflowException()
ThrowUInt32OverflowException()
ThrowInt64OverflowException()
ThrowUInt64OverflowException()
ToBoolean(System.Object)
ToBoolean(System.Object,System.IFormatProvider)
ToBoolean(System.Boolean)
ToBoolean(System.SByte)
ToBoolean(System.Char)
ToBoolean(System.Byte)
ToBoolean(System.Int16)
ToBoolean(System.UInt16)
ToBoolean(System.Int32)
ToBoolean(System.UInt32)
ToBoolean(System.Int64)
ToBoolean(System.UInt64)
ToBoolean(System.String)
ToBoolean(System.String,System.IFormatProvider)
ToBoolean(System.Single)
ToBoolean(System.Double)
ToBoolean(System.Decimal)
ToBoolean(System.DateTime)
ToChar(System.Object)
ToChar(System.Object,System.IFormatProvider)
ToChar(System.Boolean)
ToChar(System.Char)
ToChar(System.SByte)
ToChar(System.Byte)
ToChar(System.Int16)
ToChar(System.UInt16)
ToChar(System.Int32)
ToChar(System.UInt32)
ToChar(System.Int64)
ToChar(System.UInt64)
ToChar(System.String)
ToChar(System.String,System.IFormatProvider)
ToChar(System.Single)
ToChar(System.Double)
ToChar(System.Decimal)
ToChar(System.DateTime)
ToSByte(System.Object)
ToSByte(System.Object,System.IFormatProvider)
ToSByte(System.Boolean)
ToSByte(System.SByte)
ToSByte(System.Char)
ToSByte(System.Byte)
ToSByte(System.Int16)
ToSByte(System.UInt16)
ToSByte(System.Int32)
ToSByte(System.UInt32)
ToSByte(System.Int64)
ToSByte(System.UInt64)
ToSByte(System.Single)
ToSByte(System.Double)
ToSByte(System.Decimal)
ToSByte(System.String)
ToSByte(System.String,System.IFormatProvider)
ToSByte(System.DateTime)
ToByte(System.Object)
ToByte(System.Object,System.IFormatProvider)
ToByte(System.Boolean)
ToByte(System.Byte)
ToByte(System.Char)
ToByte(System.SByte)
ToByte(System.Int16)
ToByte(System.UInt16)
ToByte(System.Int32)
ToByte(System.UInt32)
ToByte(System.Int64)
ToByte(System.UInt64)
ToByte(System.Single)
ToByte(System.Double)
ToByte(System.Decimal)
ToByte(System.String)
ToByte(System.String,System.IFormatProvider)
ToByte(System.DateTime)
ToInt16(System.Object)
ToInt16(System.Object,System.IFormatProvider)
ToInt16(System.Boolean)
ToInt16(System.Char)
ToInt16(System.SByte)
ToInt16(System.Byte)
ToInt16(System.UInt16)
ToInt16(System.Int32)
ToInt16(System.UInt32)
ToInt16(System.Int16)
ToInt16(System.Int64)
ToInt16(System.UInt64)
ToInt16(System.Single)
ToInt16(System.Double)
ToInt16(System.Decimal)
ToInt16(System.String)
ToInt16(System.String,System.IFormatProvider)
ToInt16(System.DateTime)
ToUInt16(System.Object)
ToUInt16(System.Object,System.IFormatProvider)
ToUInt16(System.Boolean)
ToUInt16(System.Char)
ToUInt16(System.SByte)
ToUInt16(System.Byte)
ToUInt16(System.Int16)
ToUInt16(System.Int32)
ToUInt16(System.UInt16)
ToUInt16(System.UInt32)
ToUInt16(System.Int64)
ToUInt16(System.UInt64)
ToUInt16(System.Single)
ToUInt16(System.Double)
ToUInt16(System.Decimal)
ToUInt16(System.String)
ToUInt16(System.String,System.IFormatProvider)
ToUInt16(System.DateTime)
ToInt32(System.Object)
ToInt32(System.Object,System.IFormatProvider)
ToInt32(System.Boolean)
ToInt32(System.Char)
ToInt32(System.SByte)
ToInt32(System.Byte)
ToInt32(System.Int16)
ToInt32(System.UInt16)
ToInt32(System.UInt32)
ToInt32(System.Int32)
ToInt32(System.Int64)
ToInt32(System.UInt64)
ToInt32(System.Single)
ToInt32(System.Double)
ToInt32(System.Decimal)
ToInt32(System.String)
ToInt32(System.String,System.IFormatProvider)
ToInt32(System.DateTime)
ToUInt32(System.Object)
ToUInt32(System.Object,System.IFormatProvider)
ToUInt32(System.Boolean)
ToUInt32(System.Char)
ToUInt32(System.SByte)
ToUInt32(System.Byte)
ToUInt32(System.Int16)
ToUInt32(System.UInt16)
ToUInt32(System.Int32)
ToUInt32(System.UInt32)
ToUInt32(System.Int64)
ToUInt32(System.UInt64)
ToUInt32(System.Single)
ToUInt32(System.Double)
ToUInt32(System.Decimal)
ToUInt32(System.String)
ToUInt32(System.String,System.IFormatProvider)
ToUInt32(System.DateTime)
ToInt64(System.Object)
ToInt64(System.Object,System.IFormatProvider)
ToInt64(System.Boolean)
ToInt64(System.Char)
ToInt64(System.SByte)
ToInt64(System.Byte)
ToInt64(System.Int16)
ToInt64(System.UInt16)
ToInt64(System.Int32)
ToInt64(System.UInt32)
ToInt64(System.UInt64)
ToInt64(System.Int64)
ToInt64(System.Single)
ToInt64(System.Double)
ToInt64(System.Decimal)
ToInt64(System.String)
ToInt64(System.String,System.IFormatProvider)
ToInt64(System.DateTime)
ToUInt64(System.Object)
ToUInt64(System.Object,System.IFormatProvider)
ToUInt64(System.Boolean)
ToUInt64(System.Char)
ToUInt64(System.SByte)
ToUInt64(System.Byte)
ToUInt64(System.Int16)
ToUInt64(System.UInt16)
ToUInt64(System.Int32)
ToUInt64(System.UInt32)
ToUInt64(System.Int64)
ToUInt64(System.UInt64)
ToUInt64(System.Single)
ToUInt64(System.Double)
ToUInt64(System.Decimal)
ToUInt64(System.String)
ToUInt64(System.String,System.IFormatProvider)
ToUInt64(System.DateTime)
ToSingle(System.Object)
ToSingle(System.Object,System.IFormatProvider)
ToSingle(System.SByte)
ToSingle(System.Byte)
ToSingle(System.Char)
ToSingle(System.Int16)
ToSingle(System.UInt16)
ToSingle(System.Int32)
ToSingle(System.UInt32)
ToSingle(System.Int64)
ToSingle(System.UInt64)
ToSingle(System.Single)
ToSingle(System.Double)
ToSingle(System.Decimal)
ToSingle(System.String)
ToSingle(System.String,System.IFormatProvider)
ToSingle(System.Boolean)
ToSingle(System.DateTime)
ToDouble(System.Object)
ToDouble(System.Object,System.IFormatProvider)
ToDouble(System.SByte)
ToDouble(System.Byte)
ToDouble(System.Int16)
ToDouble(System.Char)
ToDouble(System.UInt16)
ToDouble(System.Int32)
ToDouble(System.UInt32)
ToDouble(System.Int64)
ToDouble(System.UInt64)
ToDouble(System.Single)
ToDouble(System.Double)
ToDouble(System.Decimal)
ToDouble(System.String)
ToDouble(System.String,System.IFormatProvider)
ToDouble(System.Boolean)
ToDouble(System.DateTime)
ToDecimal(System.Object)
ToDecimal(System.Object,System.IFormatProvider)
ToDecimal(System.SByte)
ToDecimal(System.Byte)
ToDecimal(System.Char)
ToDecimal(System.Int16)
ToDecimal(System.UInt16)
ToDecimal(System.Int32)
ToDecimal(System.UInt32)
ToDecimal(System.Int64)
ToDecimal(System.UInt64)
ToDecimal(System.Single)
ToDecimal(System.Double)
ToDecimal(System.String)
ToDecimal(System.String,System.IFormatProvider)
ToDecimal(System.Decimal)
ToDecimal(System.Boolean)
ToDecimal(System.DateTime)
ToDateTime(System.DateTime)
ToDateTime(System.Object)
ToDateTime(System.Object,System.IFormatProvider)
ToDateTime(System.String)
ToDateTime(System.String,System.IFormatProvider)
ToDateTime(System.SByte)
ToDateTime(System.Byte)
ToDateTime(System.Int16)
ToDateTime(System.UInt16)
ToDateTime(System.Int32)
ToDateTime(System.UInt32)
ToDateTime(System.Int64)
ToDateTime(System.UInt64)
ToDateTime(System.Boolean)
ToDateTime(System.Char)
ToDateTime(System.Single)
ToDateTime(System.Double)
ToDateTime(System.Decimal)
ToString(System.Object)
ToString(System.Object,System.IFormatProvider)
ToString(System.Boolean)
ToString(System.Boolean,System.IFormatProvider)
ToString(System.Char)
ToString(System.Char,System.IFormatProvider)
ToString(System.SByte)
ToString(System.SByte,System.IFormatProvider)
ToString(System.Byte)
ToString(System.Byte,System.IFormatProvider)
ToString(System.Int16)
ToString(System.Int16,System.IFormatProvider)
ToString(System.UInt16)
ToString(System.UInt16,System.IFormatProvider)
ToString(System.Int32)
ToString(System.Int32,System.IFormatProvider)
ToString(System.UInt32)
ToString(System.UInt32,System.IFormatProvider)
ToString(System.Int64)
ToString(System.Int64,System.IFormatProvider)
ToString(System.UInt64)
ToString(System.UInt64,System.IFormatProvider)
ToString(System.Single)
ToString(System.Single,System.IFormatProvider)
ToString(System.Double)
ToString(System.Double,System.IFormatProvider)
ToString(System.Decimal)
ToString(System.Decimal,System.IFormatProvider)
ToString(System.DateTime)
ToString(System.DateTime,System.IFormatProvider)
ToString(System.String)
ToString(System.String,System.IFormatProvider)
ToByte(System.String,System.Int32)
ToSByte(System.String,System.Int32)
ToInt16(System.String,System.Int32)
ToUInt16(System.String,System.Int32)
ToInt32(System.String,System.Int32)
ToUInt32(System.String,System.Int32)
ToInt64(System.String,System.Int32)
ToUInt64(System.String,System.Int32)
ToString(System.Byte,System.Int32)
ToString(System.Int16,System.Int32)
ToString(System.Int32,System.Int32)
ToString(System.Int64,System.Int32)
ThrowInvalidBase()
ToOctalString(System.UInt64)
ToBase64String(System.Byte[])
ToBase64String(System.Byte[],System.Base64FormattingOptions)
ToBase64String(System.Byte[],System.Int32,System.Int32)
ToBase64String(System.Byte[],System.Int32,System.Int32,System.Base64FormattingOptions)
ToBase64String(System.ReadOnlySpan`1<System.Byte>,System.Base64FormattingOptions)
ToBase64CharArray(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32)
ToBase64CharArray(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32,System.Base64FormattingOptions)
TryToBase64Chars(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>,System.Int32&,System.Base64FormattingOptions)
ConvertToBase64WithLineBreaks(System.Span`1<System.Char>,System.ReadOnlySpan`1<System.Byte>)
ToBase64_CalculateAndValidateOutputLength(System.Int32,System.Boolean)
FromBase64String(System.String)
TryFromBase64String(System.String,System.Span`1<System.Byte>,System.Int32&)
TryFromBase64Chars(System.ReadOnlySpan`1<System.Char>,System.Span`1<System.Byte>,System.Int32&)
FromBase64CharArray(System.Char[],System.Int32,System.Int32)
FromHexString(System.String)
FromHexString(System.ReadOnlySpan`1<System.Char>)
FromHexString(System.ReadOnlySpan`1<System.Byte>)
FromHexString(System.String,System.Span`1<System.Byte>,System.Int32&,System.Int32&)
FromHexString(System.ReadOnlySpan`1<System.Char>,System.Span`1<System.Byte>,System.Int32&,System.Int32&)
FromHexString(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&,System.Int32&)
ToHexString(System.Byte[])
ToHexString(System.Byte[],System.Int32,System.Int32)
ToHexString(System.ReadOnlySpan`1<System.Byte>)
TryToHexString(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>,System.Int32&)
TryToHexString(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&)
ToHexStringLower(System.Byte[])
ToHexStringLower(System.Byte[],System.Int32,System.Int32)
ToHexStringLower(System.ReadOnlySpan`1<System.Byte>)
TryToHexStringLower(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Char>,System.Int32&)
TryToHexStringLower(System.ReadOnlySpan`1<System.Byte>,System.Span`1<System.Byte>,System.Int32&)