public static bool CheckArgs(int min, int max, string name, IList <IExpression> ArgList, BCValue Retval) { if (ArgList.Count < min) { if (min == max) { Retval.SetError(1, $"{name} requires {min} args, not {ArgList.Count}."); } else { Retval.SetError(1, $"{name} requires {min} to {max} args, not {ArgList.Count}."); } return(false); } if (ArgList.Count > max) { if (min == max) { Retval.SetError(1, $"{name} requires {min} args, not {ArgList.Count}."); } else { Retval.SetError(1, $"{name} requires {min} to {max} args, not {ArgList.Count}."); } return(false); } return(true); }
// name and argName are used only for error messages public static bool CheckValueRange(string name, double value, string argName, double min, double max, BCValue Retval) { if (!Double.IsNaN(min) && value < min) { Retval.SetError(1, $"{name} {argName} argument is {value} but must be >= {min}"); return(false); } if (!Double.IsNaN(max) && value > max) { Retval.SetError(1, $"{name} {argName} argument is {value} but must be <= {max}"); return(false); } return(true); }
public RunResult(string str) { Result = new BCValue(str); }
public static async Task <bool> CheckArgValue(int index, string argName, int min, int max, BCRunContext context, string name, IList <IExpression> ArgList, BCValue Retval) { if (index >= ArgList.Count) { Retval.SetError(1, $"{name} is missing the {argName} argument."); return(false); } double value = (await ArgList[index].EvalAsync(context)).AsDouble; return(CheckValueRange(name, value, argName, min, max, Retval)); }