Пример #1
0
        /// <summary>
        /// Process condition and returns condition result.
        /// </summary>
        /// <param name="command">Condition.</param>
        /// <param name="table">Table.</param>
        /// <param name="row">Row.</param>
        /// <param name="from">Use state FROM keyword.</param>
        public static bool Process(string command, MochaTableResult table, MochaRow row, bool from)
        {
            ConditionType type;

            if (!IsCondition(command, out type))
            {
                return(false);
            }

            string[]     parts  = GetConditionParts(command, MhqlEng_CONDITION_LEXER.Operators[type.ToString()]);
            Expressional value0 = GetValue(parts[0], table, row, from);
            Expressional value1 = GetValue(parts[1], table, row, from);

            if (value0.Type != value1.Type)
            {
                throw new InvalidCastException("Value types is are not compatible!");
            }

            switch (type)
            {
            case ConditionType.EQUAL: return(value0.Equal(value1));

            case ConditionType.NOTEQUAL: return(value0.NotEqual(value1));

            case ConditionType.BIGGER: return(value0.Bigger(value1));

            case ConditionType.LOWER: return(value0.Lower(value1));

            case ConditionType.BIGGEREQ: return(value0.BiggerEqual(value1));

            case ConditionType.LOWEREQ: return(value0.LowerEqual(value1));

            default: return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// Returns true if lower, returns false if not.
 /// </summary>
 /// <param name="v">Value to compare.</param>
 public bool Lower(Expressional v)
 {
     if (Type == ExpressionType.Boolean)
     {
         return(Value.ToString() == "False" && v.Value.ToString() == "True");
     }
     else if (Type == ExpressionType.Char)
     {
         return((int)Value < (int)v.Value);
     }
     else if (Type == ExpressionType.Arithmetic)
     {
         return(decimal.Parse(Value.ToString()) < decimal.Parse(v.Value.ToString()));
     }
     throw new InvalidCastException("LOWER operator is cannot compatible this data type!");
 }
Пример #3
0
 /// <summary>
 /// Returns true if biggereq, returns false if not.
 /// </summary>
 /// <param name="v">Value to compare.</param>
 public bool BiggerEqual(Expressional v)
 {
     if (Type == ExpressionType.Boolean)
     {
         return
             ((Value.ToString() == "True" && v.Value.ToString() == "False") ||
              (Value.ToString() == v.Value.ToString()));
     }
     else if (Type == ExpressionType.Char)
     {
         return((int)Value >= (int)v.Value);
     }
     else if (Type == ExpressionType.Arithmetic)
     {
         return(decimal.Parse(Value.ToString()) >= decimal.Parse(v.Value.ToString()));
     }
     throw new InvalidCastException("BIGGEREQ operator is cannot compatible this data type!");
 }
Пример #4
0
 /// <summary>
 /// Returns true if not equals, returns false if not.
 /// </summary>
 /// <param name="v">Value to compare.</param>
 public bool NotEqual(Expressional v) =>
 Value.ToString() != v.Value.ToString();
Пример #5
0
 /// <summary>
 /// Returns true if equals, returns false if not.
 /// </summary>
 /// <param name="v">Value to compare.</param>
 public bool Equal(Expressional v) =>
 Value.ToString() == v.Value.ToString();