Esempio n. 1
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }

            if (a is double && b is double)
            {
                return((double)a + (double)b);
            }
            else if (a is DateTime && b is double)
            {
                return(((DateTime)a).AddDays((double)b));
            }
            else if (a is string || b is string)
            {
                return(string.Format("{0}{1}", a, b));
            }
            else
            {
                throw new Exceptions.UnexpectedTypeException(a.GetType());
            }
        }
Esempio n. 2
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }

            else if (double.TryParse(a.ToString(), out double aNumber) && double.TryParse(b.ToString(), out double bNumber))
            {
                return(aNumber + bNumber);
            }
            else if (a is DateTime && double.TryParse(b.ToString(), out bNumber))
            {
                return(((DateTime)a).AddDays(bNumber));
            }
            else if (a is string || b is string)
            {
                return(string.Format("{0}{1}", a, b));
            }
            else
            {
                throw new Exceptions.UnexpectedTypeException(a.GetType());
            }
        }
Esempio n. 3
0
        public override object EvalValue(Func <string, object> context)
        {
            object value = Operand1.EvalValue(context);

            if (value.ConvertToBoolean())
            {
                return(true);
            }
            else
            {
                value = Operand2.EvalValue(context);
                return(value.ConvertToBoolean());
            }
        }
Esempio n. 4
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }

            if (a is double && b is double)
            {
                return((double)a % (double)b);
            }
            else
            {
                throw new Exceptions.UnexpectedTypeException(a.GetType());
            }
        }
Esempio n. 5
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }

            if (a is double && b is double)
            {
                return((double)a * (double)b);
            }
            else
            {
                throw new FormatException();
            }
        }
Esempio n. 6
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }

            if (a is decimal && b is decimal)
            {
                return(Convert.ToDecimal(Math.Pow(Convert.ToDouble(a), Convert.ToDouble(b))));
            }
            else
            {
                throw new Exceptions.UnexpectedTypeException(a.GetType());
            }
        }
Esempio n. 7
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }
            else if (a is decimal && b is decimal)
            {
                return((decimal)a - (decimal)b);
            }
            else if (a is DateTime && b is decimal)
            {
                return(((DateTime)a).AddDays(-1 * Convert.ToDouble(b)));
            }
            else
            {
                throw new UnexpectedTypeException(a.GetType());
            }
        }
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(false);
            }
            Type type = a.GetType();

            if (type != b.GetType())
            {
                throw new Exceptions.UnexpectedTypeException(type, b.GetType());
            }
            int result = 0;

            if (type == typeof(decimal))
            {
                result = Comparer <decimal> .Default.Compare((decimal)a, (decimal)b);
            }
            else if (type == typeof(DateTime))
            {
                result = Comparer <DateTime> .Default.Compare((DateTime)a, (DateTime)b);
            }
            else if (type == typeof(String))
            {
                result = Comparer <String> .Default.Compare((String)a, (String)b);
            }
            else if (type == typeof(bool))
            {
                result = Comparer <bool> .Default.Compare((bool)a, (bool)b);
            }
            else
            {
                throw new NotSupportedException();
            }
            return(interpret(result));
        }
Esempio n. 9
0
        public override object EvalValue(Func <string, object> context)
        {
            object a = Operand1.EvalValue(context);
            object b = Operand2.EvalValue(context);

            if (a == null || b == null)
            {
                return(null);
            }
            else if (double.TryParse(a.ToString(), out double aNumber) && double.TryParse(b.ToString(), out double bNumber))
            {
                return(aNumber - bNumber);
            }
            else if (a is DateTime && b is double)
            {
                return(((DateTime)a).AddDays(-1 * Convert.ToDouble(b)));
            }
            else
            {
                throw new UnexpectedTypeException(a.GetType());
            }
        }