public override bool Evaluate(Resource[] args, ref Resource @object) { Decimal sum = InitialValue; foreach (Resource r in args) { if (r == null) { return(false); } if (!(r is Literal)) { return(false); } try { Decimal v = (Decimal)Convert.ChangeType(((Literal)r).ParseValue(), typeof(Decimal)); sum = Combine(sum, v); } catch (FormatException) { return(false); } } Resource newvalue = Literal.FromValue(sum); if (@object == null) { @object = newvalue; return(true); } else { return(@object.Equals(newvalue)); } }
public override bool Evaluate(Resource[] args, ref Resource @object) { if (args.Length != 2) { return(false); } if (args[0] == null || !(args[0] is Literal)) { return(false); } if (args[1] == null || !(args[1] is Literal)) { return(false); } try { Decimal left = (Decimal)Convert.ChangeType(((Literal)args[0]).ParseValue(), typeof(Decimal)); Decimal right = (Decimal)Convert.ChangeType(((Literal)args[1]).ParseValue(), typeof(Decimal)); Resource newvalue = Literal.FromValue(Evaluate(left, right)); if (@object == null) { @object = newvalue; return(true); } else { return(@object.Equals(newvalue)); } } catch (FormatException) { return(false); } }
public override Resource Evaluate(Resource[] args) { if (args.Length != 2) { throw new InvalidOperationException("This relation takes two arguments."); } Resource left = args[0]; Resource right = args[1]; bool result = Evaluate(new Resource[] { left }, ref right); return(Literal.FromValue(result)); }
public override bool Evaluate(Resource[] args, ref Resource @object) { if (args.Length != 1) { return(false); } if (args[0] == null && @object == null) { return(false); } if ((args[0] != null && !(args[0] is Literal)) || (@object != null && !(@object is Literal))) { return(false); } try { if (args[0] == null) { Decimal right = (Decimal)Convert.ChangeType(((Literal)@object).ParseValue(), typeof(Decimal)); Decimal left = EvaluateReverse(right); if (left == Decimal.MinValue) { return(false); } args[0] = Literal.FromValue(left); return(true); } else { Decimal left = (Decimal)Convert.ChangeType(((Literal)args[0]).ParseValue(), typeof(Decimal)); Decimal right = EvaluateForward(left); if (@object == null) { @object = Literal.FromValue(right); return(true); } else { Decimal right2 = (Decimal)Convert.ChangeType(((Literal)@object).ParseValue(), typeof(Decimal)); return(right == right2); } } } catch (FormatException) { return(false); } }