Class Prompt
Utilities for getting input from an interactive console.
Inheritance
Inherited Members
Namespace: McMaster.Extensions.CommandLineUtils
Assembly: McMaster.Extensions.CommandLineUtils.dll
Syntax
public static class Prompt
  Methods
| Improve this Doc View SourceGetInt(String, Nullable<Int32>, Nullable<ConsoleColor>, Nullable<ConsoleColor>)
Gets an integer response from the console after displaying a prompt.
Declaration
public static int GetInt(string prompt, int? defaultAnswer = default(int? ), ConsoleColor? promptColor = default(ConsoleColor? ), ConsoleColor? promptBgColor = default(ConsoleColor? ))
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | prompt | The question to display on the command line  | 
      
| System.Nullable<System.Int32> | defaultAnswer | If the user provides an empty response, which value should be returned  | 
      
| System.Nullable<System.ConsoleColor> | promptColor | The console color to display  | 
      
| System.Nullable<System.ConsoleColor> | promptBgColor | The console background color for the prompt  | 
      
Returns
| Type | Description | 
|---|---|
| System.Int32 | The response as a number  | 
      
GetPassword(String, Nullable<ConsoleColor>, Nullable<ConsoleColor>)
Gets a response that contains a password. Input is masked with an asterisk.
Declaration
public static string GetPassword(string prompt, ConsoleColor? promptColor = default(ConsoleColor? ), ConsoleColor? promptBgColor = default(ConsoleColor? ))
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | prompt | The question to display on command line  | 
      
| System.Nullable<System.ConsoleColor> | promptColor | The console color to use for the prompt  | 
      
| System.Nullable<System.ConsoleColor> | promptBgColor | The console background color for the prompt  | 
      
Returns
| Type | Description | 
|---|---|
| System.String | The password as plaintext. Can be null or empty.  | 
      
GetPasswordAsSecureString(String, Nullable<ConsoleColor>, Nullable<ConsoleColor>)
Gets a response as a SecureString object. Input is masked with an asterisk.
Declaration
public static SecureString GetPasswordAsSecureString(string prompt, ConsoleColor? promptColor = default(ConsoleColor? ), ConsoleColor? promptBgColor = default(ConsoleColor? ))
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | prompt | The question to display on the command line  | 
      
| System.Nullable<System.ConsoleColor> | promptColor | The console color to use for the prompt  | 
      
| System.Nullable<System.ConsoleColor> | promptBgColor | The console background color for the prompt  | 
      
Returns
| Type | Description | 
|---|---|
| System.Security.SecureString | A finalized SecureString object, may be empty.  | 
      
GetString(String, Nullable<String>, Nullable<ConsoleColor>, Nullable<ConsoleColor>)
Gets a console response from the console after displaying a prompt.
Declaration
public static string? GetString(string prompt, string? defaultValue = default(string? ), ConsoleColor? promptColor = default(ConsoleColor? ), ConsoleColor? promptBgColor = default(ConsoleColor? ))
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | prompt | The question to display on command line  | 
      
| System.Nullable<System.String> | defaultValue | If the user enters a blank response, return this value instead.  | 
      
| System.Nullable<System.ConsoleColor> | promptColor | The console color to use for the prompt  | 
      
| System.Nullable<System.ConsoleColor> | promptBgColor | The console background color for the prompt  | 
      
Returns
| Type | Description | 
|---|---|
| System.Nullable<System.String> | The response the user gave. Can be null or empty  | 
      
GetYesNo(String, Boolean, Nullable<ConsoleColor>, Nullable<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.
Declaration
public static bool GetYesNo(string prompt, bool defaultAnswer, ConsoleColor? promptColor = default(ConsoleColor? ), ConsoleColor? promptBgColor = default(ConsoleColor? ))
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | prompt | The question to display on the command line  | 
      
| System.Boolean | defaultAnswer | If the user provides an empty response, which value should be returned  | 
      
| System.Nullable<System.ConsoleColor> | promptColor | The console color to display  | 
      
| System.Nullable<System.ConsoleColor> | promptBgColor | The console background color for the prompt  | 
      
Returns
| Type | Description | 
|---|---|
| System.Boolean | True is 'yes'  |