Table of Contents

Class Prompt

Namespace
McMaster.Extensions.CommandLineUtils
Assembly
McMaster.Extensions.CommandLineUtils.dll

Utilities for getting input from an interactive console.

public static class Prompt
Inheritance
object
Prompt

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

prompt string

The question to display on the command line

defaultAnswer int?

If the user provides an empty response, which value should be returned

promptColor ConsoleColor?

The console color to display

promptBgColor ConsoleColor?

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

prompt string

The question to display on command line

promptColor ConsoleColor?

The console color to use for the prompt

promptBgColor ConsoleColor?

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

prompt string

The question to display on the command line

promptColor ConsoleColor?

The console color to use for the prompt

promptBgColor ConsoleColor?

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

prompt string

The question to display on command line

defaultValue string

If the user enters a blank response, return this value instead.

promptColor ConsoleColor?

The console color to use for the prompt

promptBgColor ConsoleColor?

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

prompt string

The question to display on the command line

defaultAnswer bool

If the user provides an empty response, which value should be returned

promptColor ConsoleColor?

The console color to display

promptBgColor ConsoleColor?

The console background color for the prompt

Returns

bool

True is 'yes'