public class Function_DecimalMultiply : CustomCalculationFunctionBase { public Function_DecimalMultiply() { SetName("decmultiply"); SetDescription("Multiplies all the decimal numbers in a range of cells."); SetCategory("DecimalMath"); SetArgList(new[] { "number0", "number1" }); SetArgDescriptions(new[] { "Number0, number1, ... are arguments for which you want to multiply" }); } protected override CalculationValue Evaluate(CalculationNumberStack numberStack, int argumentCount) { decimal? num = 1; foreach (var value in this.GetArguments(numberStack, argumentCount, false)) { decimal? num2; if (value.IsError) return new CalculationValue(value.ToErrorValue()); if (!value.ToNullableDecimal(out num2)) return new CalculationValue(new CalculationErrorValue(CalculationErrorCode.Value)); num *= num2; } return new CalculationValue(num); } public override int MaxArgs { get { return 0x7fffffff; } } public override int MinArgs { get { return 2; } } } public class Function_Subtract : CustomCalculationFunctionBase { public Function_Subtract() { SetName("subtract"); SetDescription("Returns the first argument minus the second argument as a decimal."); SetCategory("DecimalMath"); SetArgList(new[] { "number0", "number1" }); SetArgDescriptions(new[] { "The number to be subtracted from", "The number to subtract from the first argument" }); } protected override CalculationValue Evaluate(CalculationNumberStack numberStack, int argumentCount) { decimal? num; decimal? num2; var value2 = numberStack.Pop(); var value = numberStack.Pop(); if (value.IsError) return new CalculationValue(value.ToErrorValue()); if (value2.IsError) return new CalculationValue(value2.ToErrorValue()); bool flag = value.IsDateTime; bool flag2 = value2.IsDateTime; if (flag || flag2) { long ticks; if (flag && flag2) ticks = value.ToDateTime(CultureInfo.InvariantCulture).Subtract(value2.ToDateTime(CultureInfo.InvariantCulture)).Ticks; else { double dnum; if (!flag) return new CalculationValue(new CalculationErrorValue(CalculationErrorCode.Value)); if (!value2.ToDouble(out dnum)) return new CalculationValue(new CalculationErrorValue(CalculationErrorCode.Num)); ticks = value.ToDateTime(CultureInfo.InvariantCulture).AddDays(-dnum).Ticks; } return new CalculationValue(new DateTime(ticks)); } if (!value.ToNullableDecimal(out num) || !value2.ToNullableDecimal(out num2)) return new CalculationValue(new CalculationErrorValue(CalculationErrorCode.Value)); return new CalculationValue(num - num2); } public override int MaxArgs { get { return 2; } } public override int MinArgs { get { return 2; } } }