YetAnotherConsoleTables 3.2.0

dotnet add package YetAnotherConsoleTables --version 3.2.0                
NuGet\Install-Package YetAnotherConsoleTables -Version 3.2.0                
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="YetAnotherConsoleTables" Version="3.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YetAnotherConsoleTables --version 3.2.0                
#r "nuget: YetAnotherConsoleTables, 3.2.0"                
#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 YetAnotherConsoleTables as a Cake Addin
#addin nuget:?package=YetAnotherConsoleTables&version=3.2.0

// Install YetAnotherConsoleTables as a Cake Tool
#tool nuget:?package=YetAnotherConsoleTables&version=3.2.0                

YetAnotherConsoleTables NuGet Made in Ukraine

Advanced library to output your POCO collections in a table view in a console (supports multi-line data, attributes settings, output customization).

Contents

Getting started (basic)

Install the package:

PM> Install-Package YetAnotherConsoleTables

Write a code:

using YetAnotherConsoleTables;

class Something
{
  private static Random rnd = new Random();

  public int Property1 { get; set; } = rnd.Next(99, 10001);
  public string Field1 = "My String";
}

class Program
{
  var data = Enumerable.Range(0, 5).Select(x => new Something()).ToList();
  ConsoleTable.From(data).Write();
}

Output:

-------------------------
| Property1 | Field1    |
-------------------------
| 4299      | My String |
-------------------------
| 475       | My String |
-------------------------
| 4142      | My String |
-------------------------
| 239       | My String |
-------------------------
| 6547      | My String |
-------------------------

Advanced Features

Attributes

TableMemberAttribute

Sets properties of the table member, such as display name, default value, order, and min width.

TableIgnoreAttribute

Instructs the library to ignore marked public field or property.

TableMemberConverterAttribute

Instructs the library to use the specified TableMemberConverter when converting the member to string. You can create your own TableMemberConverter by inheriting TableMemberConverter or TableMemberConverter<T>.

For .NET 7 and upper, the generic version of the attribute is available - TableMemberConverterAttribute<TConverter>. The non-generic version is deprecated for these platforms and will be removed because the generic attribute provides more compile-time guarantees on the type parameter.

If you need to pass constructor arguments to your TableMemberConverter, you can specify them using the ConstructorArgs property of the TableMemberConverterAttribute. This allows you to create re-usable, configurable, common converters.

Combined Example

using YetAnotherConsoleTables.Attributes;

class MyConverter : TableMemberConverter<int>
{
  public override string Convert(int value) => $"MyConverter:{value}";
}

class MyConverterWithParam : TableMemberConverter<int>
{
  private readonly string _prefix;

  public MyConverterWithParam(string prefix) => _prefix = prefix;

  public override string Convert(int value) => $"{_prefix}{value}";
}

class Something
{
  private static Random rnd = new Random();

  [TableMember(DisplayName = "My Integer Property")]
  [TableMemberConverter(typeof(MyConverter))]
  public int Property1 { get; set; } = rnd.Next(99, 10001);

  [TableIgnore]
  public string Field1 = "My String";

  [TableMember(Order = 1, DefaultValue = "Null Value")]
  public string Property2 { get; set; } = null;

  [TableMember(MinWidth = 20)]
  [TableMemberConverter(typeof(MyConverterWithParam), ConstructorArgs = new[] { "MyConv1:" })]
  public int Property3 { get; set; } = rnd.Next(100, 999);
}

Output:

-----------------------------------------------------------
| Property2  | My Integer Property | Property3            |
-----------------------------------------------------------
| Null Value | MyConverter:4292    | MyConv1:512          |
-----------------------------------------------------------
| Null Value | MyConverter:4697    | MyConv1:696          |
-----------------------------------------------------------
| Null Value | MyConverter:1672    | MyConv1:234          |
-----------------------------------------------------------
| Null Value | MyConverter:6317    | MyConv1:754          |
-----------------------------------------------------------
| Null Value | MyConverter:4804    | MyConv1:562          |
-----------------------------------------------------------

Multi-line Data

The library supports multi-line strings in data and the TableDisplayName attribute.

class Something
{
  private static Random rnd = new Random();

  [TableDisplayName("My\r\nInteger\r\nProperty")]
  public int Property1 { get; set; } = rnd.Next(99, 10001);
  public string Field1;

  public Something()
  {
    Field1 = 
      string.Join(Environment.NewLine, Enumerable.Range(1, rnd.Next(0, 4)).Select(x => new string('A', rnd.Next(1, 5))));
  }
}

Output:

---------------------
| My       | Field1 |
| Integer  |        |
| Property |        |
---------------------
| 8542     | AAAA   |
---------------------
| 7476     | A      |
|          | AA     |
|          | AAAA   |
---------------------
| 5718     |        |
---------------------
| 9074     | A      |
|          | AA     |
|          | AA     |
---------------------
| 4717     | AAA    |
|          | AAAA   |
---------------------

Output Customization

You can customize the table view using the Write method overloads which accept the ConsoleTableFormat parameter. You can use one of four library-defined styles or create your own.

Default Style: Write() or Write(ConsoleTableFormat.Default)

-------------------------
| Property1 | Field1    |
-------------------------
| 2094      | My String |
-------------------------
| 5183      | My String |
-------------------------
| 5589      | My String |
-------------------------

Plus Style: Write(ConsoleTableFormat.Plus)

+-----------+-----------+
| Property1 | Field1    |
+-----------+-----------+
| 9748      | My String |
+-----------+-----------+
| 5487      | My String |
+-----------+-----------+
| 7850      | My String |
+-----------+-----------+

Header Style: Write(ConsoleTableFormat.Header)

|===========|===========|
| Property1 | Field1    |
|===========|===========|
| 4118      | My String |
|-----------|-----------|
| 5309      | My String |
|-----------|-----------|
| 4051      | My String |
|-----------|-----------|

Github Markdown: Write(ConsoleTableFormat.GithubMarkdown)

| Property1 | Property2 |
|-----------|-----------|
| AA        | 30        |
| AB        | 35        |
| BB        | 40        |

Defined Custom Style

class MyFormat : ConsoleTableFormat
{
  public MyFormat() : base(columnDelimiter: ':',
    intersection: '+', borders: ConsoleTableFormat.Borders.HeaderDelimiter | ConsoleTableFormat.Borders.RowDelimiter)
  {

  }
}
 Property1 : Field1    
-----------+-----------
 461       : My String 
-----------+-----------
 7180      : My String 
-----------+-----------
 6146      : My String 
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETFramework 4.6.1

  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on YetAnotherConsoleTables:

Package Downloads
YetAnotherConsoleTables.Logger

The logger extensions for table logging using the YetAnotherConsoleTables library.

YetAnotherConsoleTables.CommonConverters

The set of common table member converters for the YetAnotherConsoleTables library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0 4,682 6/4/2023
3.1.0 138 5/28/2023
3.0.1 771 2/14/2021
3.0.1-alpha 289 2/8/2021
3.0.0 5,746 11/2/2019
2.0.0 1,138 5/23/2018
1.2.0 1,020 4/16/2018
1.1.0 996 3/21/2018
1.0.0 1,026 3/12/2018

- Added MinWidth property to [TableMember]. Use it to set the minimal width of a table column
- Added ConstructorArgs property to [TableMemberConverter]. Use it to pass arguments to a converter constructor