コード例 #1
0
 private void DisplayChoices(PromptChoiceItem <T> defaultChoice)
 {
     Console.WriteLine(Message);
     foreach (var choice in _choices)
     {
         Console.WriteLine(FormatDefault(choice, defaultChoice.Equals(choice)));
     }
 }
コード例 #2
0
        private T GetUserChoice(PromptChoiceItem <T> defaultChoice)
        {
            var userChoice = Console.ReadLine();

            try
            {
                return(_choices.Single(choice => choice.Equals(userChoice)).Value);
            }
            catch (InvalidOperationException)
            {
                return(defaultChoice.Value);
            }
        }
コード例 #3
0
 private static string FormatDefault(PromptChoiceItem <T> choiceItem, bool isDefault) => $"{choiceItem}{(isDefault ? DefaultPostfix : string.Empty)}";