本文整理汇总了C#中IConsole.ValidatePrompt方法的典型用法代码示例。如果您正苦于以下问题:C# IConsole.ValidatePrompt方法的具体用法?C# IConsole.ValidatePrompt怎么用?C# IConsole.ValidatePrompt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConsole
的用法示例。
在下文中一共展示了IConsole.ValidatePrompt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public Prompt Run(IDictionary<string, string> args, IConsole console)
{
if (args.ContainsKey("name"))
{
console.WarningLine("Hello " + args["name"]);
var integerStr = console.ValidatePrompt("Enter integer: ", Helpers.Validation.IntValidator(1, 10), "Not an integer.");
var doubleStr = console.ValidatePrompt("Enter double: ", Helpers.Validation.DoubleValidator(), "Not an double.");
var boolStr = console.ValidatePrompt("Enter bool: ", Helpers.Validation.BoolValidator(), "Not an bool.");
}
else
{
var name = console.Prompt("What's your name? ");
var iceCreamChoice = console.ValidatePrompt("Pick your favorite ice cream (vanilla, chocolate): ",
s => {
var isVanilla = s.Equals("vanilla", StringComparison.OrdinalIgnoreCase);
var isChocolate = s.Equals("chocolate", StringComparison.OrdinalIgnoreCase);
return isVanilla || isChocolate;
},
//2 alternate ways to pass in a Validation function
//s => new[] { "vanilla", "chocolate" }.Any(iceCream => iceCream.Equals(s, StringComparison.OrdinalIgnoreCase)),
//Validate, //or write the validation function elsewhere and reference it
"Please choose from the specified list.");
console.SuccessLine("HelloWorld " + name + "! You like " + iceCreamChoice + " ice cream!");
}
return Prompt.Continue;
}