private static EvaluationResult EvaluateComparison(EvaluationResult left, EvaluationResult right, Func<int, bool> operation) { var type = PrimitiveType.InstanceFor(left.Value); var result = type.ComparisonOperator(left, right); if (result.IsInt32) return Result(operation(result.Int32Value)); return result; }
private EvaluationResult EvaluateLogicalOr(EvaluationResult left, EvaluationResult right) { var type = PrimitiveType.InstanceFor(left.Value); return type.LogicalOr(left, right); }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { if (value.IsInt32 && other.IsInt32) return Result(value.Int32Value.CompareTo(other.Int32Value)); return Error("Integer values can only be compared to other integer values"); }
public override EvaluationResult LogicalOr(EvaluationResult value, EvaluationResult other) { return value; }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { if (value.IsBool && other.IsBool) return Result(value.BoolValue == other.BoolValue); return Error("Boolean values can only be compared to other boolean values"); }
public override EvaluationResult LogicalOr(EvaluationResult value, EvaluationResult other) { if (value.BoolValue) return value; return other; }
public abstract EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other);
public override EvaluationResult LogicalOr(EvaluationResult value, EvaluationResult other) { return(value); }
public abstract EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other);
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return(value); }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { return(value); }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return(Error("'null' values can not be compared")); }
private static EvaluationResult ConvertToBool(EvaluationResult value) { //TODO: Proper type conversion if (value.IsBool) return value; return Error(string.Format("Value '{0}' is not convertible to a boolean.", value)); }
public abstract EvaluationResult LogicalOr(EvaluationResult value, EvaluationResult other);
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { return(Result(value.IsNull && other.IsNull)); }
protected EvaluationResult Result(object value) { return(EvaluationResult.Result(value)); }
protected EvaluationResult Error(string message) { return(EvaluationResult.Error(message)); }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return Error("Boolean values can only be compared to other boolean values"); }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return(Error("Boolean values can only be compared to other boolean values")); }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { if (value.IsInt32 && other.IsInt32) return Result(value.Int32Value == other.Int32Value); return Error("Integer values can only be compared to other integer values"); }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { return Result(value.IsNull && other.IsNull); }
public override EvaluationResult LogicalAnd(EvaluationResult value, EvaluationResult other) { return other; }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return Error("'null' values can not be compared"); }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { if (value.IsString && other.IsString) return Result(value.StringValue == other.StringValue); return Result(false); }
public override EvaluationResult EqualityOperator(EvaluationResult value, EvaluationResult other) { return value; }
private static EvaluationResult EvaluateArithmetic(EvaluationResult left, EvaluationResult right, Func<EvaluationResult, EvaluationResult, EvaluationResult> operation) { //TODO: Proper type conversion var leftValue = ConvertToInt(left); if (leftValue.IsError) return leftValue; var rightValue = ConvertToInt(right); if (rightValue.IsError) return rightValue; return operation(leftValue, rightValue); }
public override EvaluationResult ComparisonOperator(EvaluationResult value, EvaluationResult other) { return value; }
private static EvaluationResult ConvertToInt(EvaluationResult value) { //TODO: Proper type conversion if (value.IsInt32) return value; return Error(string.Format("Value '{0}' is not convertible to an integer.", value)); }
private static EvaluationResult EvaluateEquality(EvaluationResult left, EvaluationResult right, Func<bool, bool> operation) { var type = PrimitiveType.InstanceFor(left.Value); var result = type.EqualityOperator(left, right); if (result.IsBool) return Result(operation(result.BoolValue)); return result; }
public override EvaluationResult LogicalAnd(EvaluationResult value, EvaluationResult other) { return(other); }