private static ReflectionResult SetSimple(string property, object source, object value) { PropertyInfoResult info = AcquirePropertyInfo(property, source); if (info.ReflectionException != null) { return(new ReflectionResult { ReflectionException = info.ReflectionException }); } value = TypeConverter.To(value, info.PropertyInfo.PropertyType); try { info.PropertyInfo.SetValue(source, value, null); return(new ReflectionResult()); } catch (TargetInvocationException Te) { if (Te.InnerException != null) { throw Te.InnerException; } throw; } }
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)); }
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)); }
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)); }
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); } }
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)); }