Skip to content

Instantly share code, notes, and snippets.

@aholmes
Created November 22, 2022 16:35
Show Gist options
  • Save aholmes/6f3700d68f7e42f336c9f3cc65e42f4c to your computer and use it in GitHub Desktop.
Save aholmes/6f3700d68f7e42f336c9f3cc65e42f4c to your computer and use it in GitHub Desktop.
Wrapper for System.Console in C#
namespace aholmes.Writer
{
/// <summary>
/// Wraps System.Console
/// </summary>
public class ConsoleWrapper : IConsole
{
/// <inheritdoc/>
public void Write(string value) => Console.Write(value);
/// <inheritdoc/>
public void WriteLine() => Console.WriteLine();
/// <inheritdoc/>
public void WriteLine(string value) => Console.WriteLine(value);
/// <inheritdoc/>
public ConsoleKeyInfo ReadKey() => Console.ReadKey();
/// <inheritdoc/>
public int Read() => Console.Read();
/// <inheritdoc/>
public string ReadLine() => Console.ReadLine();
}
/// <summary>
/// An interface for mocking <see cref="Console"/>
/// </summary>
public interface IConsole
{
/// <summary>
/// <see cref="Console.Write(string)"/>
/// </summary>
/// <param name="value"></param>
void Write(string value);
/// <summary>
/// <see cref="Console.WriteLine()"/>
/// </summary>
void WriteLine();
/// <summary>
/// <see cref="Console.WriteLine(string)"/>
/// </summary>
/// <param name="value"></param>
void WriteLine(string value);
public ConsoleKeyInfo ReadKey();
/// <summary>
/// <see cref="Console.Read()"/>
/// </summary>
/// <returns></returns>
public int Read();
/// <summary>
/// <see cref="Console.ReadLine()"/>
/// </summary>
/// <returns></returns>
public string ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment