public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); bool rhsBool = TypeCoercer.CoerceToType <bool>(this, rhsResult); return(!rhsBool); }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(-rhsFloat); }
public override object Evaluate(UnityELEvaluator context) { object amount = Rhs.Evaluate(context); float floatAmount = TypeCoercer.CoerceToType <float>(this, amount); float floatCurrent = 0; // If the value doesn't already exists (and we can detect that) we start with zero. bool readCurrentValue = true; if (Lhs is ExistsSupport) { readCurrentValue = ((ExistsSupport)Lhs).Exists(context); } if (readCurrentValue) { object current = Lhs.Evaluate(context); floatCurrent = TypeCoercer.CoerceToType <float>(this, current); } float result = floatCurrent + floatAmount; ((AssignableToken)Lhs).Assign(context, result); return(result); }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); int rhsInt = TypeCoercer.CoerceToType <int>(this, rhsResult); return(~rhsInt); }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); return(lhsResult ?? rhsResult); }
public override object Evaluate(UnityELEvaluator context) { object value = Rhs.Evaluate(context); ((AssignableToken)Lhs).Assign(context, value); return(value); }
protected bool DoEvaluate(UnityELEvaluator context, object lhsResult) { Type lhsType = lhsResult?.GetType(); // Otherwise the rhs must identify the type to match object rhsResult = Rhs.Evaluate(context); if (rhsResult == null) { return(false); } string rhsString = TypeCoercer.CoerceToType <string>(this, rhsResult); // Special handling for some primitives if (rhsString.Equals("int", StringComparison.InvariantCultureIgnoreCase) || rhsString.Equals("integer", StringComparison.InvariantCultureIgnoreCase)) { // Is it an int? if (typeof(int).Equals(lhsType)) { return(true); } else if (typeof(float).Equals(lhsType)) { // We use floats internally, so we allow them to be considered as 'ints' if it would // not result in the loss of any data float floatValue = (float)lhsResult; int intValue = (int)floatValue; return(intValue == floatValue); } else { return(false); } } else if (rhsString.Equals("float", StringComparison.InvariantCultureIgnoreCase)) { // Allow floats or ints? return(typeof(float).Equals(lhsType) || typeof(int).Equals(lhsType)); } else if (rhsString.Equals("bool", StringComparison.InvariantCultureIgnoreCase) || rhsString.Equals("boolean", StringComparison.InvariantCultureIgnoreCase)) { return(typeof(bool).Equals(lhsType)); } else if (lhsType != null) { // Otherwise we must match the end of the type name return(lhsType.FullName.EndsWith(rhsString, StringComparison.InvariantCultureIgnoreCase)); } else { return(false); } }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(FastExponent(lhsFloat, rhsFloat)); }
public override object Evaluate( EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context) { var left = (bool[]) Lhs.Evaluate(eventsPerStream, isNewData, context); var right = (bool[]) Rhs.Evaluate(eventsPerStream, isNewData, context); if (left == null || right == null) { // null comparison return null; } return Arrays.AreEqual(left, right) ^ parent.IsNotEquals; }
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)); }
public override object Evaluate( EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context) { var left = (int[]) Lhs.Evaluate(eventsPerStream, isNewData, context); var right = (int[]) Rhs.Evaluate(eventsPerStream, isNewData, context); bool result; if (left == null) { result = right == null; } else { result = right != null && Arrays.AreEqual(left, right); } result = result ^ parent.IsNotEquals; return result; }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); if (lhsResult is float || lhsResult is int) { float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(lhsFloat == rhsFloat); } else if (lhsResult != null) { return(lhsResult.Equals(rhsResult)); } else { return(rhsResult == null); } }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); string rhsTypeName = TypeCoercer.CoerceToType <string>(this, rhsResult); if (rhsTypeName == null) { throw new ParserException("Right-hand side of 'as' evaluated to null"); } if ("int".Equals(rhsTypeName)) { return(TypeCoercer.CoerceToType <int>(this, lhsResult)); } else if ("float".Equals(rhsTypeName)) { return(TypeCoercer.CoerceToType <float>(this, lhsResult)); } else if ("string".Equals(rhsTypeName)) { return(TypeCoercer.CoerceToType <string>(this, lhsResult)); } else if ("bool".Equals(rhsTypeName)) { return(TypeCoercer.CoerceToType <bool>(this, lhsResult)); } else { Type type = Type.GetType(rhsTypeName); if (type == null) { throw new ParserException($"Could not resolve type from string: {rhsTypeName}"); } return(TypeCoercer.CoerceToType(type, this, lhsResult)); } }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); if (lhsResult.GetType() == typeof(string)) { // String addition string lhsString = TypeCoercer.CoerceToType <string>(this, lhsResult); string rhsString = TypeCoercer.CoerceToType <string>(this, rhsResult); return(lhsString + rhsString); } else { // Mathmatic addition float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(lhsFloat + rhsFloat); } }
public override object Evaluate(UnityELEvaluator context) { object lhsResult = Lhs.Evaluate(context); object rhsResult = Rhs.Evaluate(context); // See if the lhs supports an operator overload for the rhs if (lhsResult != null) { OperatorInfo info = FindOperator(lhsResult.GetType(), "op_Multiply", rhsResult); if (info != null) { object coercedRhs = TypeCoercer.CoerceToType(info.OperandType, this, rhsResult); return(info.Method.Invoke(null, new object[] { lhsResult, coercedRhs })); } } // Otherwise just use a float multiplication float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult); float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult); return(lhsFloat * rhsFloat); }
public override object Evaluate(UnityELEvaluator context) { float oldValue = 0; // If the value doesn't already exists (and we can detect that) we start with zero. bool readCurrentValue = true; if (Rhs is ExistsSupport) { readCurrentValue = ((ExistsSupport)Rhs).Exists(context); } if (readCurrentValue) { object current = Rhs.Evaluate(context); oldValue = TypeCoercer.CoerceToType <float>(this, current); } float newValue = oldValue - 1; ((AssignableToken)Rhs).Assign(context, newValue); return(newValue); }
public override object Evaluate(UnityELEvaluator context) { object rhsResult = Rhs.Evaluate(context); if (rhsResult is string) { string s = (string)rhsResult; return(s.Length == 0); } else if (rhsResult is ICollection) { ICollection collection = (ICollection)rhsResult; return(collection.Count == 0); } else if (rhsResult is IEnumerable) { IEnumerable enumer = (IEnumerable)rhsResult; return(!enumer.GetEnumerator().MoveNext()); } else { return(rhsResult == null); } }
public IComparable RhsTyped(IModel model) { return((IComparable)Rhs.Evaluate(model)); }
public bool RhsTyped(IModel model) { return((bool)TypeConverter.To(Rhs.Evaluate(model), ParameterType)); }
public override object InternalEvaluate(IModel model) { return(model[LhsTyped(model)] = Rhs.Evaluate(model)); }