public override bool Evaluate(RuntimeValues runtimeEnv) { object leftVal = left.GetRuntimeValue(runtimeEnv); object rightVal = right.GetRuntimeValue(runtimeEnv); IComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture); int compare; if (leftVal is IComparable) { compare = comparer.Compare(leftVal, rightVal); } else if (rightVal is IComparable) { compare = -comparer.Compare(rightVal, leftVal); } else { // Only do this if neither version is comparable. // The reason is IComparable objects can change the // meaning of Equals in surprising ways if necessary, // such as for version matching. if (opToken == XppTokenType.EQ) { return(Equals(leftVal, rightVal)); } if (opToken == XppTokenType.NEQ) { return(!Equals(leftVal, rightVal)); } throw new ArgumentException("Can't perform a compare on two objects that don't implement IComparable"); } switch (opToken) { case XppTokenType.LT: return(compare < 0); case XppTokenType.LTE: return(compare <= 0); case XppTokenType.EQ: return(compare == 0); case XppTokenType.NEQ: return(compare != 0); case XppTokenType.GT: return(compare > 0); case XppTokenType.GTE: return(compare >= 0); default: throw new ArgumentException("Program error: Unexpected comparison operator in XppCompareExpr"); } }
public override bool Evaluate(RuntimeValues runtimeEnv) { Regex regex; object patternObj = pattern.GetRuntimeValue(runtimeEnv); if (patternObj is string) { regex = new Regex((string)patternObj, DEFAULT_REGEX_OPTIONS); } else if (patternObj is Regex) { regex = (Regex)patternObj; } else { throw new ArgumentException("Right-hand side of regex operator wasn't a string or regex"); } return(not ^ regex.IsMatch(val.GetRuntimeValue(runtimeEnv).ToString())); }