Created
September 20, 2017 14:08
-
-
Save randyburden/e84ff18dd1f846872273467d9b2d923b to your computer and use it in GitHub Desktop.
C# extension/helper class for writing colored output to the console. This is sort-of a workaround of not being able to extend the static Console class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Utilities.Extensions | |
{ | |
public static class ConsoleColorExtensions | |
{ | |
/// <summary> | |
/// Writes the specified string value, followed by the current line terminator, to the standard output stream. | |
/// </summary> | |
/// <example> | |
/// ConsoleColor.Green.WriteLine("The task executed successfully"); | |
/// </example> | |
/// <param name="foregroundColor">Foreground color.</param> | |
/// <param name="value">The value to write.</param> | |
public static void WriteLine(this ConsoleColor foregroundColor, string value) | |
{ | |
var originalForegroundColor = Console.ForegroundColor; | |
Console.ForegroundColor = foregroundColor; | |
Console.WriteLine(value); | |
Console.ForegroundColor = originalForegroundColor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment