Пример #1
0
 private void Evaluate(CultureInfo culture)
 {
     _evaluated = TypeConverter.TryTo(_value, typeof(bool), culture) ??
                  TypeConverter.TryTo(_value, typeof(decimal), culture) ??
                  TryParseDateTime(_value, culture) ??
                  TryParseDate(_value, culture) ??
                  _value;
 }
Пример #2
0
 public string LhsTyped(IModel model)
 {
     if (!(Lhs is Constant) && (model.Get(Lhs.AsParsable())?.Full ?? false))
     {
         return(Lhs.AsParsable());
     }
     return((string)TypeConverter.To(Lhs.Evaluate(model), typeof(string)));
 }
        public decimal RhsTyped(IModel model)
        {
            if (Rhs == null)
            {
                throw ExpressionParseException.MissingExpression("rhs").Decorate(Token);
            }
            var raw = Rhs.Evaluate(model);

            if (raw == null)
            {
                throw ExpressionParseException.UnexpectedNullValue("rhs").Decorate(Token);
            }
            return((decimal)TypeConverter.To(raw, ParameterType));
        }
Пример #4
0
        protected bool IsEqual(object lhs, object rhs)
        {
            if (TypeConverter.IsNumeric(lhs) && TypeConverter.IsNumeric(rhs))
            {
                lhs = (decimal)TypeConverter.To(lhs, typeof(decimal));
                rhs = (decimal)TypeConverter.To(rhs, typeof(decimal));
            }
            if ((TypeConverter.IsEnum(lhs) && rhs is string) ||
                (lhs is string && TypeConverter.IsEnum(rhs)))
            {
                return(Equals(lhs?.ToString(), rhs?.ToString()));
            }

            return(Equals(lhs, rhs));
        }
Пример #5
0
        protected int Compare(IComparable lhs, IComparable rhs)
        {
            if (lhs == null || rhs == null)
            {
                return(lhs?.CompareTo(rhs) ?? (-1 * rhs?.CompareTo(lhs) ?? 0));
            }

            if (TypeConverter.IsNumeric(lhs) && TypeConverter.IsNumeric(rhs))
            {
                lhs = (decimal)TypeConverter.To(lhs, typeof(decimal));
                rhs = (decimal)TypeConverter.To(rhs, typeof(decimal));
            }
            if (!Equals(lhs.GetType(), rhs.GetType()))
            {
                throw ComparisionException.UnComparable(lhs.GetType(), rhs.GetType()).Decorate(Token);
            }
            return(lhs.CompareTo(rhs));
        }
Пример #6
0
        public override object Evaluate(IModel model)
        {
            var parameters = new List <object>();

            for (int i = 0; i < _function.Arguments.Length; i++)
            {
                var arg = _function.Arguments[i];
                if (!arg.Params)
                {
                    var    node  = _nested.Nodes[i];
                    object value = node.Evaluate(model);
                    parameters.Add(TypeConverter.To(value, _function.Arguments[i].Type));
                }
                else
                {
                    for (int pi = i; pi < _nested.Nodes.Count; pi++)
                    {
                        var    node  = _nested.Nodes[pi];
                        object value = node.Evaluate(model);
                        parameters.Add(TypeConverter.To(value, _function.Arguments[i].Type));
                    }
                }
            }
            try
            {
                return(_function.Evaluate(parameters.ToArray()));
            }
            catch (ExceptionWithContext EWC)
            {
                if (EWC.Context == null)
                {
                    throw ExceptionWithContext.MakePartial(EWC).Decorate(Token);
                }
                else
                {
                    throw EWC;
                }
            }
            catch (Exception e)
            {
                throw FunctionEvaluationException.EvaluationError(e).Decorate(Token);
            }
        }
Пример #7
0
        public override object Evaluate(IModel model)
        {
            var nestedValue = (bool)TypeConverter.To(Nested.Evaluate(model), typeof(bool));

            return(!nestedValue);
        }
 public bool RhsTyped(IModel model)
 {
     return((bool)TypeConverter.To(Rhs.Evaluate(model), ParameterType));
 }
 public bool ConditionTyped(IModel model)
 {
     return((bool)TypeConverter.To(Condition.Evaluate(model), ParameterType));
 }
Пример #10
0
 private void Evaluate(CultureInfo culture)
 {
     _evaluated = TypeConverter.TryTo(_name, typeof(bool), culture) ??
                  TypeConverter.TryTo(_name, typeof(decimal), culture);
     _constant = _evaluated != null;
 }