Exemplo 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());
            }
        }
Exemplo 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());
            }
        }
Exemplo 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());
            }
        }
Exemplo 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());
            }
        }
Exemplo 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();
            }
        }
Exemplo 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());
            }
        }
Exemplo 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());
            }
        }
Exemplo n.º 8
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(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));
        }
Exemplo 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());
            }
        }