private static ResultValue Add(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if ((left is ResultNumberValue) && (right is ResultNumberValue)) { decimal result = ((ResultNumberValue)left).Value + ((ResultNumberValue)right).Value; return new ResultNumberValue(result); } else if ((left is ResultDateValue) && (right is ResultNumberValue)) { DateTime result = ((ResultDateValue)left).Value.AddDays(Decimal.ToDouble(((ResultNumberValue)right).Value)); return new ResultDateValue(result); } else if ((left is ResultStringValue)) { string result = ((ResultStringValue)left).Value + right.StrValue(); return new ResultStringValue(result); } else { throw new LaxerCalculateException(); } }
private static ResultValue And(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if ((left is ResultBoolValue) && (right is ResultBoolValue)) { bool result = ((ResultBoolValue)left).Value && ((ResultBoolValue)right).Value; return new ResultBoolValue(result); } else { throw new LaxerCalculateException(); } }
private static ResultValue XorAndPower(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if ((left is ResultNumberValue) && (right is ResultNumberValue)) { double result = Math.Pow(Decimal.ToDouble(((ResultNumberValue)left).Value), Decimal.ToDouble(((ResultNumberValue)right).Value)); return new ResultNumberValue(new decimal(result)); } else if ((left is ResultBoolValue) && (right is ResultBoolValue)) { bool result = ((ResultBoolValue)left).Value ^ ((ResultBoolValue)right).Value; return new ResultBoolValue(result); } else { throw new LaxerCalculateException(); } }
private static ResultValue Remainder(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if ((left is ResultNumberValue) && (right is ResultNumberValue)) { decimal result = ((ResultNumberValue)left).Value % ((ResultNumberValue)right).Value; return new ResultNumberValue(result); } else { throw new LaxerCalculateException(); } }
private static ResultValue NotEqual(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if (left.GetType().Equals(right.GetType())) { bool result = left.ComparaValue().CompareTo(right.ComparaValue()) != 0; return new ResultBoolValue(result); } else { throw new LaxerCalculateException(); } }
private static ResultValue Multiply(ResultValue left, ResultValue right) { if (ResultValue.HasNullResult(left, right)) { return ResultNullValue.Instance; } if ((left is ResultNumberValue) && (right is ResultNumberValue)) { decimal result = ((ResultNumberValue)left).Value * ((ResultNumberValue)right).Value; return new ResultNumberValue(result); } else if ((left is ResultStringValue) && (right is ResultNumberValue)) { StringBuilder sb = new StringBuilder(); string baseString = ((ResultStringValue)left).Value; int loopCount = Decimal.ToInt32(((ResultNumberValue)right).Value); for (int i = 0; i < loopCount; i++) { sb.Append(baseString); } return new ResultStringValue(sb.ToString()); } else { throw new LaxerCalculateException(); } }