LSL.AbstractConsole
1.0.2
dotnet add package LSL.AbstractConsole --version 1.0.2
NuGet\Install-Package LSL.AbstractConsole -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LSL.AbstractConsole" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LSL.AbstractConsole --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LSL.AbstractConsole, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LSL.AbstractConsole as a Cake Addin #addin nuget:?package=LSL.AbstractConsole&version=1.0.2 // Install LSL.AbstractConsole as a Cake Tool #tool nuget:?package=LSL.AbstractConsole&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LSL.AbstractConsole
This library provides an abstraction to write to a console.
Basics
The Main interface IConsole
is defined as follows
/// <summary>
/// The basic abstraction of a console to write to
/// </summary>
public interface IConsole
{
/// <summary>
/// Write to the console
/// </summary>
/// <param name="text">The text to write</param>
/// <param name="includeNewLine">Append a new line to the text if <c>true</c></param>
/// <param name="args">Any arguments if the <c>text</c> has placeholders in it</param>
/// <returns></returns>
IConsole Write(string text, bool includeNewLine, IEnumerable<object> args);
}
A default implementation called DefaultConsole
can be instantied and used as follows:
using LSL.AbstractConsole;
...
using var writer = new StringWriter();
var console = new DefaultConsole(writer);
console.Write("some text {0}", false, new object[] { "to display" });
var output = writer.ToString();
/* output will contain the following
some text to display
*/
NOTE:
Console.Out
can be used as the output to just output to the console.
Extension methods
The following extesion methods are available to align with string-based Console.XXX
methods:
public static class ConsoleExtensions
{
private static readonly IEnumerable<object> _emptyArgs = Enumerable.Empty<object>();
/// <summary>
/// Writes the placeholder formatted <c>text</c> to the <c>IConsole</c> with the provided args
/// </summary>
/// <param name="console"></param>
/// <param name="text">The placeholder formatted message</param>
/// <param name="args">The arguments to use for the placeholders</param>
/// <returns>The original <c>IConsole</c> to chain calls with</returns>
public static IConsole Write(this IConsole console, string text, params object[] args) => console.Write(text, false, args);
/// <summary>
/// Writes the <c>text</c> to the <c>IConsole</c>
/// </summary>
/// <param name="console"></param>
/// <param name="text">The text to output</param>
/// <returns>The original <c>IConsole</c> to chain calls with</returns>
public static IConsole Write(this IConsole console, string text) => console.Write(text, false, _emptyArgs);
/// <summary>
/// Writes the <c>text</c> to the <c>IConsole</c> including an environment specific <c>NewLine</c>
/// </summary>
/// <param name="console"></param>
/// <param name="text">The text to output</param>
/// <returns>The original <c>IConsole</c> to chain calls with</returns>
public static IConsole WriteLine(this IConsole console, string text) => console.Write(text, true, _emptyArgs);
/// <summary>
/// Writes the placeholder formatted <c>text</c> to the <c>IConsole</c> including an environment specific <c>NewLine</c>
/// </summary>
/// <param name="console"></param>
/// <param name="text">The placeholder formatted message</param>
/// <param name="args">The arguments to use for the placeholders</param>
/// <returns>The original <c>IConsole</c> to chain calls with</returns>
public static IConsole WriteLine(this IConsole console, string text, params object[] args) => console.Write(text, true, args);
/// <summary>
/// Writes a new line with no content
/// </summary>
/// <param name="console"></param>
/// <returns>The original <c>IConsole</c> to chain calls with</returns>
public static IConsole WriteLine(this IConsole console) => console.WriteLine(string.Empty, true, _emptyArgs);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LSL.AbstractConsole:
Package | Downloads |
---|---|
LSL.AbstractConsole.ServiceProvider
Provides quick registration of the LSL.AbstractConsole standard types for an IServiceCollection |
GitHub repositories
This package is not used by any popular GitHub repositories.