/// <summary> /// Display DbExpression in a human-readable string. /// </summary> /// <returns>String containing human-readable version of the DbExpression.</returns> public override string ToString() { string ret = ""; ret += "("; if (LeftTerm is DbExpression) { ret += ((DbExpression)LeftTerm).ToString(); } else { ret += LeftTerm.ToString(); } ret += " " + Operator.ToString() + " "; if (RightTerm is DbExpression) { ret += ((DbExpression)RightTerm).ToString(); } else { ret += RightTerm.ToString(); } ret += ")"; return(ret); }
public virtual bool Calculate() { if ((LeftTerm == null) && (RightTerm == null)) { return(false); } if (LeftTerm == null) { return(RightTerm.Calculate()); } if (RightTerm == null) { return(LeftTerm.Calculate()); } return(BoolOperator()); } // Calculate
public void Evaluate() { if (!IsValid()) { throw new Exception($"Evaluation of predicate has failed. Missing value {LeftTerm.Id}."); } if (Evaluated) { return; } try { var operatorType = Type.GetType($"Reasoning.Core.Models.Operators.{Enum.GetName(typeof(OperatorType), Operator)}, Reasoning.Core"); var operatorInstance = (IOperator)Activator.CreateInstance(operatorType); Result = operatorInstance.Compare(LeftTerm.GetValue(), RightTerm.GetValue()); Evaluated = true; } catch (Exception ex) { throw new Exception($"Unknown operator instance of predicate", ex); } }
public bool IsValid() { return(!LeftTerm.IsEmpty() && !RightTerm.IsEmpty()); }
public string GetMissingVariableId() { return(LeftTerm.IsEmpty() ? LeftTerm.Id : null); }
} // constructor protected override bool BoolOperator() { return(LeftTerm.Calculate() || RightTerm.Calculate()); } // BoolOperator