-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prompts.cs
35 lines (33 loc) · 1.11 KB
/
Prompts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
internal static class Prompts
{
public delegate bool ConditionMethod(params object[] args);
public static string PromptUntilConditionMet(string startingMessage, string problemMessage, ConditionMethod conditionMethod, params object[] args)
{
Console.Write(startingMessage);
string option = Console.ReadLine() ?? "exit";
if (option == "exit") return "exit";
args[0] = option;
while (!conditionMethod(args))
{
Console.Write(problemMessage);
option = Console.ReadLine() ?? "exit";
if (option == "exit") return "exit";
args[0] = option;
}
return option;
}
public static string SamePromptUntilConditionMet(string message, ConditionMethod conditionMethod, params object[] args)
{
string option = "";
args[0] = option;
do
{
Console.Write(message);
option = Console.ReadLine() ?? "exit";
if (option == "exit") return "exit";
args[0] = option;
}
while (!conditionMethod(args));
return option;
}
}