Пример #1
0
 public virtual void InitBaseTypeList()
 {
     BaseTypeSequence.Clear();
     BaseTypeSequence.AddRange(new Type[] {
         typeof(string), typeof(Complex), typeof(Double), typeof(Single), typeof(Decimal),
         typeof(BigInteger),
         typeof(UInt64), typeof(Int64), typeof(UInt32), typeof(Int32), typeof(UInt16), typeof(Int16), typeof(byte), typeof(sbyte), typeof(bool)
     });
 }
Пример #2
0
        public virtual void InitTypeConverters()
        {
            bool useComplex = BaseTypeSequence.Contains(typeof(Complex));
            bool useBigInt  = BaseTypeSequence.Contains(typeof(BigInteger));
            //->string
            Type T = typeof(string);

            foreach (Type t in BaseTypeSequence)
            {
                if (t != T)
                {
                    TypeConverters.Add(t, T, ConvertAnyToString);
                }
            }
            //->Complex
            if (useComplex)
            {
                TypeConverters.Add(typeof(sbyte), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(byte), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(Int16), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(UInt16), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(Int32), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(UInt32), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(Int64), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(UInt64), typeof(Complex), ConvertAnyToComplex);
                TypeConverters.Add(typeof(Single), typeof(Complex), ConvertAnyToComplex);
                if (useBigInt)
                {
                    TypeConverters.Add(typeof(BigInteger), typeof(Complex), ConvertBigIntToComplex);
                }
            }
            //->BigInteger
            if (useBigInt)
            {
                TypeConverters.Add(typeof(sbyte), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(byte), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(Int16), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(UInt16), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(Int32), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(UInt32), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(Int64), typeof(BigInteger), ConvertAnyIntToBigInteger);
                TypeConverters.Add(typeof(UInt64), typeof(BigInteger), ConvertAnyIntToBigInteger);
            }

            //->Double
            TypeConverters.Add(typeof(sbyte), typeof(double), value => (double)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(double), value => (double)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(double), value => (double)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(double), value => (double)(UInt16)value);
            TypeConverters.Add(typeof(Int32), typeof(double), value => (double)(Int32)value);
            TypeConverters.Add(typeof(UInt32), typeof(double), value => (double)(UInt32)value);
            TypeConverters.Add(typeof(Int64), typeof(double), value => (double)(Int64)value);
            TypeConverters.Add(typeof(UInt64), typeof(double), value => (double)(UInt64)value);
            TypeConverters.Add(typeof(Single), typeof(double), value => (double)(Single)value);
            if (useBigInt)
            {
                TypeConverters.Add(typeof(BigInteger), typeof(double), value => ((BigInteger)value).ToDouble(null));
            }
            //->Single
            TypeConverters.Add(typeof(sbyte), typeof(Single), value => (Single)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(Single), value => (Single)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(Single), value => (Single)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(Single), value => (Single)(UInt16)value);
            TypeConverters.Add(typeof(Int32), typeof(Single), value => (Single)(Int32)value);
            TypeConverters.Add(typeof(UInt32), typeof(Single), value => (Single)(UInt32)value);
            TypeConverters.Add(typeof(Int64), typeof(Single), value => (Single)(Int64)value);
            TypeConverters.Add(typeof(UInt64), typeof(Single), value => (Single)(UInt64)value);
            if (useBigInt)
            {
                TypeConverters.Add(typeof(BigInteger), typeof(Single), value => (Single)((BigInteger)value).ToDouble(null));
            }

            //->UInt64
            TypeConverters.Add(typeof(sbyte), typeof(UInt64), value => (UInt64)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(UInt64), value => (UInt64)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(UInt64), value => (UInt64)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(UInt64), value => (UInt64)(UInt16)value);
            TypeConverters.Add(typeof(Int32), typeof(UInt64), value => (UInt64)(Int32)value);
            TypeConverters.Add(typeof(UInt32), typeof(UInt64), value => (UInt64)(UInt32)value);
            TypeConverters.Add(typeof(Int64), typeof(UInt64), value => (UInt64)(Int64)value);
            //->Int64
            TypeConverters.Add(typeof(sbyte), typeof(Int64), value => (Int64)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(Int64), value => (Int64)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(Int64), value => (Int64)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(Int64), value => (Int64)(UInt16)value);
            TypeConverters.Add(typeof(Int32), typeof(Int64), value => (Int64)(Int32)value);
            TypeConverters.Add(typeof(UInt32), typeof(Int64), value => (Int64)(UInt32)value);
            //->UInt32
            TypeConverters.Add(typeof(sbyte), typeof(UInt32), value => (UInt32)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(UInt32), value => (UInt32)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(UInt32), value => (UInt32)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(UInt32), value => (UInt32)(UInt16)value);
            TypeConverters.Add(typeof(Int32), typeof(UInt32), value => (UInt32)(Int32)value);
            //->Int32
            TypeConverters.Add(typeof(sbyte), typeof(Int32), value => (Int32)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(Int32), value => (Int32)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(Int32), value => (Int32)(Int16)value);
            TypeConverters.Add(typeof(UInt16), typeof(Int32), value => (Int32)(UInt16)value);
            //->UInt16
            TypeConverters.Add(typeof(sbyte), typeof(UInt16), value => (UInt16)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(UInt16), value => (UInt16)(byte)value);
            TypeConverters.Add(typeof(Int16), typeof(UInt16), value => (UInt16)(Int16)value);
            //->Int16
            TypeConverters.Add(typeof(sbyte), typeof(Int16), value => (Int16)(sbyte)value);
            TypeConverters.Add(typeof(byte), typeof(Int16), value => (Int16)(byte)value);
            //->byte
            TypeConverters.Add(typeof(sbyte), typeof(byte), value => (byte)(sbyte)value);
        }