public BinaryTerminal(string name) : base(name)
 {
     AstConfig.NodeCreator = (context, node) =>
     {
         node.AstNode = new LiteralExpression
         {
             Value   = ByteArrayHelpers.FromHex(node.Token.ValueString),
             SqlType = SqlType.ByteArray
         };
     };
 }
Esempio n. 2
0
        private static object ConvertType(object source, DataColumn column)
        {
            if (!(source is string))
            {
                return(source);
            }
            var sourceAsString = (string)source;

            if (column.DataType == typeof(decimal))
            {
                return(Convert.ChangeType(sourceAsString.Replace('.', ','), typeof(decimal)));
            }
            if (column.DataType == typeof(bool))
            {
                return(sourceAsString.EqualsIgnoringCase("t"));
            }
            if (column.DataType == typeof(DateTime))
            {
                DateTime dateTime;
                if (!TryParseDate(sourceAsString, out dateTime))
                {
                    const string messageFormat = "can't parse datetime from [{0}] for column [{1}]";
                    throw new InvalidOperationException(string.Format(messageFormat,
                                                                      source, column.ColumnName));
                }
                return(dateTime < minSqlDate ? (object)null : dateTime);
            }
            if (column.DataType == typeof(byte[]))
            {
                if (string.IsNullOrEmpty(sourceAsString) || sourceAsString.Length < 2)
                {
                    const string messageFormat = "can't parse byte array from [{0}] for column [{1}]";
                    throw new InvalidOperationException(string.Format(messageFormat, source, column.ColumnName));
                }
                return(ByteArrayHelpers.FromHex(sourceAsString, 2));
            }
            return(source);
        }