/// <summary> /// Select items from a group of options /// </summary> /// <param name="group">collection of options</param> /// <param name="max">max allowed selections</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static Task <IEnumerable <T> > Select <T>(IEnumerable <T> options, int max) { return(InputSelection.From <T>() .SetMaxSelected(max) .AddOption(options) .RequestInput()); }
/// <summary> /// Select item from a group of options /// </summary> /// <param name="group">collection of options</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async Task <T> Select <T>(IEnumerable <T> options) { return((await InputSelection.From <T>() .AddOption(options) .RequestInput() ).First()); }
private static async Task <string> GetProfileName() { var profiles = await JiraProfileService.GetAvailableProfiles(); var inputSelect = InputSelection .From <string>("Select a profile to delete") .AddOption(profiles); return((await inputSelect.RequestInput()).FirstOrDefault()); }
private static async void StartDemo() { const string NAME = "#BUFFER_SELECTION123#"; ConsoleBuffer.MemoriseBufferPosition(NAME); Console.WriteLine("Select 1 option"); var selection = InputSelection.From <TestClass>() .AddOption(new TestClass { Name = "option1" }) .AddOption(new TestClass { Name = "option2" }) .AddOption(new TestClass { Name = "option3" }) .AddOption(new TestClass { Name = "option4" }); var result1 = await selection.RequestInput(); Console.WriteLine($"Selected => {result1.First()}"); ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); Console.WriteLine("Select 1 to 5 options"); var selection2 = InputSelection.From <TestClass>() .SetMaxSelected(5) .AddOption(new TestClass { Name = "option1" }) .AddOption(new TestClass { Name = "option2" }) .AddOption(new TestClass { Name = "option3" }) .AddOption(new TestClass { Name = "option4" }) .AddOption(new TestClass { Name = "option5" }) .AddOption(new TestClass { Name = "option6" }) .AddOption(new TestClass { Name = "option7" }) .AddOption(new TestClass { Name = "option8" }) .AddOption(new TestClass { Name = "option9" }) .AddOption(new TestClass { Name = "option10" }) .AddOption(new TestClass { Name = "option11" }); var result2 = await selection2.RequestInput(); foreach (var r in result2) { Console.WriteLine($"Selected => {r}"); } ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); Console.WriteLine("Also works with ENUM"); var result3 = await InputSelection .FromEnum <EnumTest>() .RequestInput(); foreach (var r in result3) { Console.WriteLine($"Selected => {(int)r}"); } ConsoleI.AwaitContinue(); ConsoleBuffer.ClearBufferFrom(NAME); }