Albatross.Text.Table 8.0.11

Prefix Reserved
This package has a SemVer 2.0.0 package version: 8.0.11+c6d995b.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Albatross.Text.Table --version 8.0.11
                    
NuGet\Install-Package Albatross.Text.Table -Version 8.0.11
                    
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="Albatross.Text.Table" Version="8.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Albatross.Text.Table" Version="8.0.11" />
                    
Directory.Packages.props
<PackageReference Include="Albatross.Text.Table" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Albatross.Text.Table --version 8.0.11
                    
#r "nuget: Albatross.Text.Table, 8.0.11"
                    
#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.
#:package Albatross.Text.Table@8.0.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Albatross.Text.Table&version=8.0.11
                    
Install as a Cake Addin
#tool nuget:?package=Albatross.Text.Table&version=8.0.11
                    
Install as a Cake Tool

Albatross.Text.Table

Convert collection of objects into a tabular string format with fluent interface. Can print tabular data to console with a width limitation. The text truncate behavior of the string table can be customized for each column.

Features

  • StringTable class - A class that stores tablular data in string format and provides methods to print the data to a TextWriter with a width limitation and truncate behavior.
  • TableOptions<> class - An immutable class that contain configuration data that is used to convert instances of IEnumerable<T> into tabular text format.
  • TableOptionFactory - A threas safe factory class that contains the registrations of TableOptions<> as a dictionary of Dictionary<TypeOfT, TableOptions<T>>
  • TableOptionBuilder - A builder class that can be used to create the TableOptions class using a fluent interface.

How it works

The generic class TableOptions<T> contains the configuration of transformation from type T to string. The instance of TableOptions<T> is immutable, therefore thread safe. It can be declared manually, althrough it would be easier to create using a TableOptionBuilder<>.

The instance of TableOptions<T> class can be reused by registering it with the TableOptionFactory class. The TableOptionFactory class is thread safe and it has a static instance.

An instance of IEnumerable<T> can be transformed into a StringTable instance using the created TableOptions<T> instance.

Printing of StringTable

  • To Print the data from IEnumerable<T> to Console as a table using the code below:
      var list = new List<T>();
      ... populate the list ...
    
      // create a StringTable instance from the list using the default TableOptions<T> instance
      list.StringTable().PrintConsole();	
    
  • By default, PrintConsole will set the total width limit of the table as the Console width. A custom width can be set using
      var custom_width = 30;
      list.StringTable().AdjustColumnWidth(custom_width).Print(System.Console.Out);
    
  • The width limit of the individual columns can be configured using the fluent api. The change below set the MinWidth of Id column to 10 and Description to 0.
      list.StringTable().MinWidth(x => x.Name == "Id", 10).MinWidth(x => x.Name == "Description", 0).PrintConsole();
    
  • The StringTable.AdjustColumnWidth method will adjust column with from right to left based on its MinWidth property first. If the table width is still too large, the method will trim from right to left again without taking consideration of the MinWidth property. The method will only trim what's necessary.

Construction of TableOptions<T> Instance

TableOptions<T> class contains the configuration data that can convert the collection of T to string based tabular data. It is immutable once created and it can be created using TableOptionBuilder<T> using its fluent api.

  • Create a TableOptionBuilder<T> instance and initialize it with class properties using reflection.
      // SetColumnsByReflection will initialize the TableOptionBuilder instance with the public instance properties of class T as its columns.  It uses the default formatter: `BuilderExtensions.DefaultFormat`
      var builder = new TableOptionBuilder<T>().SetColumnsByReflection();
    
  • Further customize the builder with the desired behavior
      // format the Price column
      builder.Format("Price", "#,#0.00");
      // Customize the data retrieve function of  the Parent column
      builder.SetColumn(x => x.Parent, x => x.Parent.Name);
      // change the header of the Parent column
      builder.ColumnHeader(x => x.Parent, "ParentName");
      // change the order of the columns
      builder.ColumnOrder(x => x.Date, 99);
    
  • Once done customization, create an instance of TableOptions<T> to use.
      // Instance of TableOptions can be created directly from builder using its constructor.
      var options = new TableOptions<T>(builder);
    
  • These steps can be chained using fluent syntax
      var options = new TableOptionBuilder<T>()
      	.SetColumnsByReflection()
      	.Format("Price", "#,#0.00")
      	.SetColumn(x => x.Parent, x => x.Parent.Name)
      	.ColumnOrder(x => x.Date, 99)
      	.Build();
    
  • The instance of TableOptions<T> can be registered globally with TableOptionFactory. Note that both TableOptions<T> and TableOptionFactory are thread safe.
      // register the options instance directly
      var options = new TableOptionBuilder<T>()
      	...Customize
      	.Build();
      TableOptionFactory.Instance.Register(options);
    
      // options can be registered directly using its builder
      var builder = new TableOptionBuilder<T>();
      // customize the builder
      ...
      TableOptionFactory.Instance.Register(builder);
    
  • The instance of TableOptions<T> can be retrieved from the factory by calling the Get method. If no registration for T exists, an instance created by the default builder will be registered and returned.
      var options = TableOptionFactory.Instance.Get<T>();
    
  • TableOptions<T> class can be used to convert collection of T to StringTable with ease.
      var options = new TableOptionBuilder<T>()
      	.SetColumnsByReflection()
      	.Format("Price", "#,#0.00")
      	.Exclude("Id")
      	.Build();
    
      var list = new List<T>();
      ... populate the list ...
      list.StringTable(options).PrintConsole();
    
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Albatross.Text.Table:

Package Downloads
Albatross.Reqnroll

Reqnroll utility library

Albatross.Text.CliFormat

A library that prints text output based on the runtime format expression

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.1.0-67.main 25 9/10/2025
8.1.0-64.main 38 9/3/2025
8.0.11 54 6/27/2025
8.0.10 40 6/26/2025
8.0.8 64 4/25/2025
8.0.7 66 4/15/2025
8.0.6 83 4/9/2025
8.0.4 52 4/8/2025
8.0.1 182 3/4/2025