Class Prompt
- Namespace
- McMaster.Extensions.CommandLineUtils
- Assembly
- McMaster.Extensions.CommandLineUtils.dll
Utilities for getting input from an interactive console.
public static class Prompt
- Inheritance
-
objectPrompt
Methods
GetInt(string, int?, ConsoleColor?, ConsoleColor?)
Gets an integer response from the console after displaying a prompt.
public static int GetInt(string prompt, int? defaultAnswer = null, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null)
Parameters
promptstringThe question to display on the command line
defaultAnswerint?If the user provides an empty response, which value should be returned
promptColorConsoleColor?The console color to display
promptBgColorConsoleColor?The console background color for the prompt
Returns
- int
The response as a number
GetPassword(string, ConsoleColor?, ConsoleColor?)
Gets a response that contains a password. Input is masked with an asterisk.
public static string GetPassword(string prompt, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null)
Parameters
promptstringThe question to display on command line
promptColorConsoleColor?The console color to use for the prompt
promptBgColorConsoleColor?The console background color for the prompt
Returns
- string
The password as plaintext. Can be null or empty.
GetPasswordAsSecureString(string, ConsoleColor?, ConsoleColor?)
Gets a response as a SecureString object. Input is masked with an asterisk.
public static SecureString GetPasswordAsSecureString(string prompt, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null)
Parameters
promptstringThe question to display on the command line
promptColorConsoleColor?The console color to use for the prompt
promptBgColorConsoleColor?The console background color for the prompt
Returns
- SecureString
A finalized SecureString object, may be empty.
GetString(string, string?, ConsoleColor?, ConsoleColor?)
Gets a console response from the console after displaying a prompt.
public static string? GetString(string prompt, string? defaultValue = null, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null)
Parameters
promptstringThe question to display on command line
defaultValuestringIf the user enters a blank response, return this value instead.
promptColorConsoleColor?The console color to use for the prompt
promptBgColorConsoleColor?The console background color for the prompt
Returns
- string
The response the user gave. Can be null or empty
GetYesNo(string, bool, ConsoleColor?, ConsoleColor?)
Gets a yes/no response from the console after displaying a prompt.
The parsing is case insensitive. Valid responses include: yes, no, y, n.
public static bool GetYesNo(string prompt, bool defaultAnswer, ConsoleColor? promptColor = null, ConsoleColor? promptBgColor = null)
Parameters
promptstringThe question to display on the command line
defaultAnswerboolIf the user provides an empty response, which value should be returned
promptColorConsoleColor?The console color to display
promptBgColorConsoleColor?The console background color for the prompt
Returns
- bool
True is 'yes'