Skip to content

Instantly share code, notes, and snippets.

@randyburden
Created September 20, 2017 14:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save randyburden/e84ff18dd1f846872273467d9b2d923b to your computer and use it in GitHub Desktop.
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.
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