private void CheckForInputs(ApiInputType inputType, string s) { var inputString = InputGrammar.Parse(s); var inputVariables = inputString.Tokens.OfType <VariableInputToken>().ToArray(); var existingInputs = Inputs.Where(x => x.InputType == inputType).ToArray(); var obsoleteInputs = existingInputs.Where(x => !inputVariables.Any(y => x.Name == y.Variable)).ToArray(); foreach (var input in obsoleteInputs) { Inputs.Remove(input); } foreach (var variable in inputVariables) { if (!Inputs.Any(x => x.Name == variable.Variable)) { var insertionPoint = Inputs.BinarySearch(x => x.Name, variable.Variable); if (insertionPoint < 0) { insertionPoint = ~insertionPoint; Inputs.Insert(insertionPoint, new ApiInputModel { Name = variable.Variable, InputType = inputType }); } } } }
private string Format(string s) { return(InputGrammar.Parse(s).Format(name => Inputs.Single(x => x.Name == name).Value)); }