Table of Contents

Class ConsoleHelper

Namespace
Ecng.Common
Assembly
Ecng.Common.dll

Provides helper methods for writing colored messages to the console and reading secure passwords.

public static class ConsoleHelper
Inheritance
ConsoleHelper
Inherited Members

Fields

Error

Gets or sets the color used to display error messages.

public static ConsoleColor Error

Field Value

ConsoleColor

Info

Gets or sets the color used to display information messages.

public static ConsoleColor Info

Field Value

ConsoleColor

Success

Gets or sets the color used to display success messages.

public static ConsoleColor Success

Field Value

ConsoleColor

Warning

Gets or sets the color used to display warning messages.

public static ConsoleColor Warning

Field Value

ConsoleColor

Methods

ConsoleError(string)

Writes an error message to the console using the predefined error color.

public static void ConsoleError(this string message)

Parameters

message string

The error message to write.

ConsoleInfo(string)

Writes an information message to the console.

public static void ConsoleInfo(this string message)

Parameters

message string

The message to write.

ConsoleSuccess(string)

Writes a success message to the console using the predefined success color.

public static void ConsoleSuccess(this string message)

Parameters

message string

The success message to write.

ConsoleWarning(string)

Writes a warning message to the console using the predefined warning color.

public static void ConsoleWarning(this string message)

Parameters

message string

The warning message to write.

ConsoleWithColor(Action, ConsoleColor)

Executes the provided action while displaying console output in the specified color.

public static void ConsoleWithColor(this Action handler, ConsoleColor color)

Parameters

handler Action

The action to execute.

color ConsoleColor

The color to use for the console output.

Exceptions

ArgumentNullException

Thrown when the handler is null.

ConsoleWithColor(string, ConsoleColor)

Writes a message to the console with the specified color.

public static void ConsoleWithColor(this string message, ConsoleColor color)

Parameters

message string

The message to write.

color ConsoleColor

The color to use for the message.

ReadPassword()

Reads a password from the console without displaying it, outputting a masked version.

public static SecureString ReadPassword()

Returns

SecureString

A SecureString that contains the password.