Exemple #1
0
        public static object SqlDbTypeToVariable(SqlDbType dbType, Variable var)
        {
            switch (dbType)
            {
            case SqlDbType.SmallInt:
            case SqlDbType.Int:
            case SqlDbType.BigInt: return(var.AsInt());

            case SqlDbType.NChar:
            case SqlDbType.NText:
            case SqlDbType.NVarChar: return(var.AsString());

            case SqlDbType.Real:
            case SqlDbType.Decimal:
            case SqlDbType.SmallMoney:
            case SqlDbType.Money:
            case SqlDbType.Float: return(var.AsDouble());

            case SqlDbType.Binary:
            case SqlDbType.Bit: return(var.AsBool());

            case SqlDbType.SmallDateTime:
            case SqlDbType.Date:
            case SqlDbType.Time:
            case SqlDbType.DateTime: return(var.AsDateTime());
            }
            return(var.AsString());
        }
Exemple #2
0
        protected override Variable Evaluate(ParsingScript script)
        {
            // 1. Get the name of the variable.
            string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY);

            Utils.CheckNotEnd(script, m_name);

            // 2. Get the current value of the variable.
            ParserFunction func = ParserFunction.GetFunction(varName);

            Utils.CheckNotNull(varName, func);
            Variable currentValue = func.GetValue(script);

            Utils.CheckArray(currentValue, varName);

            // 3. Get the variable to remove.
            Variable item = Utils.GetItem(script);

            Utils.CheckNonNegativeInt(item);

            currentValue.Tuple.RemoveAt(item.AsInt());

            ParserFunction.AddGlobalOrLocalVariable(varName,
                                                    new GetVarFunction(currentValue));
            return(Variable.EmptyInstance);
        }
Exemple #3
0
        public Variable ConvertEnumToString(Variable value)
        {
            string result = "";

            if (m_enumMap != null && m_enumMap.TryGetValue(value.AsInt(), out result))
            {
                return(new Variable(result));
            }
            return(Variable.EmptyInstance);
        }
Exemple #4
0
        public void SetEnumProperty(string propName, Variable value, string baseName = "")
        {
            m_propertyMap[propName] = value;

            if (m_enumMap == null)
            {
                m_enumMap = new Dictionary <int, string>();
            }
            m_enumMap[value.AsInt()] = propName;
        }
Exemple #5
0
        public void SetEnumProperty(string propName, Variable value, string baseName = "")
        {
            m_propertyMap[propName] = value;

            string converted = Constants.ConvertName(propName);

            m_propertyStringMap[converted] = propName;

            if (m_enumMap == null)
            {
                m_enumMap = new Dictionary <int, string>();
            }
            m_enumMap[value.AsInt()] = propName;
        }
Exemple #6
0
        public static int GetSafeInt(List <Variable> args, int index, int defaultValue = 0)
        {
            if (args.Count <= index)
            {
                return(defaultValue);
            }
            Variable numberVar = args[index];

            if (numberVar.Type != Variable.VarType.NUMBER)
            {
                int num;
                if (!Int32.TryParse(numberVar.String, NumberStyles.Number,
                                    CultureInfo.InvariantCulture, out num))
                {
                    throw new ArgumentException("Expected an integer instead of [" + numberVar.AsString() + "]");
                }
                return(num);
            }
            return(numberVar.AsInt());
        }
Exemple #7
0
        public static object SqlDbTypeToType(DbType dbType, Variable var)
        {
            switch (dbType)
            {
            case DbType.Int16:
            case DbType.Int32:
            case DbType.Int64:    return(var.AsInt());

            case DbType.Double:
            case DbType.Single:   return(var.AsDouble());

            case DbType.String:   return(var.AsString());

            case DbType.Byte:
            case DbType.Boolean:  return(var.AsBool());

            case DbType.DateTime: return(var.AsDateTime());
            }
            return(var.AsString());
        }
Exemple #8
0
        public Variable GetEnumProperty(string propName, ParsingScript script, string baseName = "")
        {
            propName = Constants.ConvertName(propName);
            if (script.Prev == Constants.START_ARG)
            {
                Variable value = Utils.GetItem(script);
                if (propName == Constants.TO_STRING)
                {
                    return(ConvertEnumToString(value));
                }
                else
                {
                    return(new Variable(m_enumMap != null && m_enumMap.ContainsKey(value.AsInt())));
                }
            }

            string[] tokens = propName.Split('.');
            if (tokens.Length > 1)
            {
                propName = tokens[0];
            }

            string match = GetActualPropertyName(propName, GetAllProperties(), baseName, this);

            Variable result = GetCoreProperty(match, script);

            if (tokens.Length > 1)
            {
                result = ConvertEnumToString(result);
                if (tokens.Length > 2)
                {
                    string rest = string.Join(".", tokens, 2, tokens.Length - 2);
                    result = result.GetProperty(rest, script);
                }
            }

            return(result);
        }