private string StringifyQuestion(Question question) { string template = "{0}"; List<object> templateParams = new List<object> { question.Title }; if (answerUtils.IsDefaultValueSpecified(question.Answer) && answerUtils.AreAllowedValuesSpecified(question.Answer)) { template += " [current: '{1}', allowed: {2}]"; templateParams.Add(answerUtils.DetermineDefaultValue(question.Answer)); templateParams.Add(answerUtils.StringifyAllowedValues(question.Answer)); } else if (answerUtils.IsDefaultValueSpecified(question.Answer)) { template += " [current: '{1}']"; templateParams.Add(answerUtils.DetermineDefaultValue(question.Answer)); } else if (answerUtils.AreAllowedValuesSpecified(question.Answer)) { template += " [allowed: {1}]"; templateParams.Add(answerUtils.StringifyAllowedValues(question.Answer)); } template += ":"; return String.Format(template, templateParams.ToArray()); }
public void AddQuestion(string title, string[] allowedValues, string defaultAnswer = "", bool optionalAnswer = false) { Question question = new Question(); question.Title = title; question.Answer.Optional = optionalAnswer; question.Answer.AllowedValues = allowedValues; question.Answer.DefaultValue = defaultAnswer; Questions.Add(question); }
private void PromptForQuestionInput(Question question) { string questionStr = StringifyQuestion(question); question.Answer.Value = console.GetUserInput(questionStr).Trim(); if (answerUtils.IsEmpty(question.Answer)) { question.Answer.Value = answerUtils.DetermineDefaultValue(question.Answer); } }