示例#1
0
        protected override void InitializeConvertFuncs()
        {
            ConvertFuncs.Add(typeof(decimal).Name, sourceValue => System.Convert.ToDecimal((string)sourceValue));
            ConvertFuncs.Add(typeof(double).Name, sourceValue => System.Convert.ToDouble((string)sourceValue));
            ConvertFuncs.Add(typeof(float).Name, sourceValue => System.Convert.ToSingle((string)sourceValue));
            ConvertFuncs.Add(typeof(long).Name, sourceValue => System.Convert.ToInt64((string)sourceValue));
            ConvertFuncs.Add(typeof(ulong).Name, sourceValue => System.Convert.ToUInt64((string)sourceValue));
            ConvertFuncs.Add(typeof(int).Name, sourceValue => System.Convert.ToInt32((string)sourceValue));
            ConvertFuncs.Add(typeof(uint).Name, sourceValue => System.Convert.ToUInt32((string)sourceValue));
            ConvertFuncs.Add(typeof(short).Name, sourceValue => System.Convert.ToInt16((string)sourceValue));
            ConvertFuncs.Add(typeof(ushort).Name, sourceValue => System.Convert.ToUInt16((string)sourceValue));
            ConvertFuncs.Add(typeof(char).Name, sourceValue => System.Convert.ToChar((string)sourceValue));
            ConvertFuncs.Add(typeof(byte).Name, sourceValue => System.Convert.ToByte((string)sourceValue));
            ConvertFuncs.Add(typeof(bool).Name, sourceValue => System.Convert.ToBoolean((string)sourceValue));
            ConvertFuncs.Add(typeof(DateTime).Name, sourceValue =>
            {
                DateTime dateTime;
                bool validCast = DateTime.TryParse((string)sourceValue, out dateTime);
                if (!validCast)
                {
                    throw new TestflowDataException(ModuleErrorCode.UnsupportedTypeCast,
                                                    "Illegal string for datetime cast.");
                }
                return(dateTime);
            });
//            ConvertFuncs.Add(typeof(string).Name, sourceValue => sourceValue.ToString());
        }
示例#2
0
        protected override void InitializeConvertFuncs()
        {
            ConvertFuncs.Add(typeof(decimal).Name, sourceValue => System.Convert.ToDecimal((byte)sourceValue));
            ConvertFuncs.Add(typeof(double).Name, sourceValue => System.Convert.ToDouble((byte)sourceValue));
            ConvertFuncs.Add(typeof(float).Name, sourceValue => System.Convert.ToSingle((byte)sourceValue));
            ConvertFuncs.Add(typeof(long).Name, sourceValue => System.Convert.ToInt64((byte)sourceValue));
            ConvertFuncs.Add(typeof(ulong).Name, sourceValue => System.Convert.ToUInt64((byte)sourceValue));
            ConvertFuncs.Add(typeof(int).Name, sourceValue => System.Convert.ToInt32((byte)sourceValue));
            ConvertFuncs.Add(typeof(uint).Name, sourceValue => System.Convert.ToUInt32((byte)sourceValue));
            ConvertFuncs.Add(typeof(short).Name, sourceValue => System.Convert.ToInt16((byte)sourceValue));
            ConvertFuncs.Add(typeof(ushort).Name, sourceValue => System.Convert.ToUInt16((byte)sourceValue));
            ConvertFuncs.Add(typeof(char).Name, sourceValue => System.Convert.ToChar((byte)sourceValue));
//            ConvertFuncs.Add(typeof (byte).Name, sourceValue => System.Convert.ToByte((byte)sourceValue));
            ConvertFuncs.Add(typeof(bool).Name, sourceValue => (byte)sourceValue > 0);
            ConvertFuncs.Add(typeof(string).Name, sourceValue => sourceValue.ToString());
        }
示例#3
0
        protected override void InitializeConvertFuncs()
        {
            ConvertFuncs.Add(typeof(decimal).Name, sourceValue => (bool)sourceValue ? 1 : 0);
//            ConvertFuncs.Add(typeof(double).Name, sourceValue => sourceValue.ToString());
//            ConvertFuncs.Add(typeof(float).Name, sourceValue => sourceValue.ToString());
            ConvertFuncs.Add(typeof(long).Name, sourceValue => (long)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(ulong).Name, sourceValue => (ulong)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(int).Name, sourceValue => (int)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(uint).Name, sourceValue => (uint)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(short).Name, sourceValue => (short)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(ushort).Name, sourceValue => (ushort)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(char).Name, sourceValue => (char)((bool)sourceValue ? 1 : 0));
            ConvertFuncs.Add(typeof(byte).Name, sourceValue => (byte)((bool)sourceValue ? 1 : 0));
//            ConvertFuncs.Add(typeof(bool).Name, sourceValue => sourceValue.ToString());
            ConvertFuncs.Add(typeof(string).Name, sourceValue => sourceValue.ToString());
        }
示例#4
0
 protected override void InitializeConvertFuncs()
 {
     ConvertFuncs.Add(typeof(string).Name, sourceValue => ((DateTime)sourceValue).ToString(CommonConst.GlobalTimeFormat));
 }