Created
November 22, 2022 16:35
-
-
Save aholmes/6f3700d68f7e42f336c9f3cc65e42f4c to your computer and use it in GitHub Desktop.
Wrapper for System.Console in C#
This file contains hidden or 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
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