public override object Compute(IOperationExpressionContext context, IEnumerable <object> operands) { object result = null; object operand1 = operands.ElementAt(0); object operand2 = operands.ElementAt(1); if (operand1 is bool && operand2 is bool) { result = this.Compute((bool)operand1, (bool)operand2); } else { bool value1 = false, value2 = false; if (!bool.TryParse(operand1.ToString(), out value1)) { throw new InvalidOperationExpressionException(string.Format("{0} is not a boolean", operand1)); } if (!bool.TryParse(operand2.ToString(), out value2)) { throw new InvalidOperationExpressionException(string.Format("{0} is not a boolean", operand2)); } result = this.Compute(value1, value2); } return(result); }
private object GetSingleValue(IOperationExpressionContext context, string operand) { if (context.IsString(operand)) { return(operand.Substring(1, operand.Length - 2)); } bool bvalue = false; if (bool.TryParse(operand, out bvalue)) { return(bvalue); } long ivalue = 0L; if (long.TryParse(operand, out ivalue)) { return(ivalue); } decimal fvalue = 0M; if (decimal.TryParse(operand, out fvalue)) { return(fvalue); } return(operand); }
public override IOperationOperator CreateOperator(IOperationExpressionContext context) { if (context.AvailableOperandCount > 0) { return(new BinarySubtractionOperationOperator { OwnerRule = this, }); } else { return(new UnarySubtractionOperationOperator { OwnerRule = this, }); } }
public override object Compute(IOperationExpressionContext context, IEnumerable <object> operands) { object result = null; object operand1 = operands.ElementAt(0); object operand2 = operands.ElementAt(1); if ((operand1 is int || operand1 is long) && (operand2 is int || operand2 is long)) { result = this.Compute((long)operand1, (long)operand2); } else if ((operand1 is float || operand1 is double || operand1 is decimal) && (operand2 is float || operand2 is double || operand2 is decimal)) { result = this.Compute(Convert.ToDecimal(operand1), Convert.ToDecimal(operand2)); } else { long ivalue1 = 0L, ivalue2 = 0L; decimal fvalue1 = 0M, fvalue2 = 0M; bool isInteger1 = false, isInteger2 = false; bool isNumber1 = false, isNumber2 = false; isInteger1 = long.TryParse(operand1.ToString(), out ivalue1); isNumber1 = decimal.TryParse(operand1.ToString(), out fvalue1); isInteger2 = long.TryParse(operand2.ToString(), out ivalue2); isNumber2 = decimal.TryParse(operand2.ToString(), out fvalue2); if (!isNumber1) { throw new InvalidOperationExpressionException(string.Format("{0} is not a number", operand1)); } if (!isNumber2) { throw new InvalidOperationExpressionException(string.Format("{0} is not a number", operand2)); } if (isInteger1 && isInteger2) { result = this.Compute(ivalue1, ivalue2); } else { result = this.Compute(fvalue1, fvalue2); } } return(result); }
protected virtual bool ComputeResult(IOperationExpressionContext context, IEnumerable <object> operands) { object operand1 = operands.ElementAt(0); object operand2 = operands.ElementAt(1); if (object.ReferenceEquals(operand1, operand2)) { return(true); } if (operand1 == operand2) { return(true); } if (context.IsString(operand1) ^ context.IsString(operand2)) { return(false); } return(string.Equals(operand1.ToString(), operand2.ToString(), StringComparison.OrdinalIgnoreCase)); }
public override object Compute(IOperationExpressionContext context, IEnumerable <object> operands) { object result = null; object operand = operands.First(); if (operand is bool) { result = this.Compute((bool)operand); } else { bool value = false; if (!bool.TryParse(operand.ToString(), out value)) { throw new InvalidOperationExpressionException(string.Format("{0} is not a boolean", operand)); } result = this.Compute(value); } return(result); }
public override object Compute(IOperationExpressionContext context, IEnumerable <object> operands) { object result = null; object operand = operands.First(); if (operand is int || operand is long) { result = this.Compute((long)operand); } else if (operand is float || operand is double || operand is decimal) { result = this.Compute(Convert.ToDecimal(operand)); } else { long ivalue = 0L; decimal fvalue = 0M; bool isInteger = false; bool isNumber = false; isInteger = long.TryParse(operand.ToString(), out ivalue); isNumber = decimal.TryParse(operand.ToString(), out fvalue); if (!isNumber) { throw new InvalidOperationExpressionException(string.Format("{0} is not a number", operand)); } if (isInteger) { result = this.Compute(ivalue); } else { result = this.Compute(fvalue); } } return(result); }
public abstract object Compute(IOperationExpressionContext context, IEnumerable <object> operands);
public abstract IOperationOperator CreateOperator(IOperationExpressionContext context);
public override IOperationOperator CreateOperator(IOperationExpressionContext context) { return(new BinaryOrOperationOperator { OwnerRule = this, }); }
protected override bool ComputeResult(IOperationExpressionContext context, IEnumerable <object> operands) { return(!base.ComputeResult(context, operands)); }
public override object Compute(IOperationExpressionContext context, IEnumerable <object> operands) { return(this.ComputeResult(context, operands)); }