![]() |
VOOZH | about |
dotnet add package Albatross.Text.Table --version 9.0.3
NuGet\Install-Package Albatross.Text.Table -Version 9.0.3
<PackageReference Include="Albatross.Text.Table" Version="9.0.3" />
<PackageVersion Include="Albatross.Text.Table" Version="9.0.3" />Directory.Packages.props
<PackageReference Include="Albatross.Text.Table" />Project file
paket add Albatross.Text.Table --version 9.0.3
#r "nuget: Albatross.Text.Table, 9.0.3"
#:package Albatross.Text.Table@9.0.3
#addin nuget:?package=Albatross.Text.Table&version=9.0.3Install as a Cake Addin
#tool nuget:?package=Albatross.Text.Table&version=9.0.3Install as a Cake Tool
A .NET library that converts collections of objects into tabular string format with fluent interface. Print tabular data to console or any TextWriter with customizable width limitations and text truncation behavior for each column.
TextWriter with width limitations and customizable truncation behaviorIEnumerable<T> into tabular text formatTableOptions<T> instances with a global registryInstall-Package Albatross.Text.Table
dotnet add package Albatross.Text.Table
# Clone the repository
git clone https://github.com/RushuiGuan/text.git
cd text
# Restore dependencies
dotnet restore
# Build the project
dotnet build --configuration Release
# Run tests
dotnet test
using Albatross.Text.Table;
// Sample data class
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public DateTime Date { get; set; }
}
var products = new List<Product>
{
new Product { Id = 1, Name = "Laptop", Price = 999.99m, Date = DateTime.Now },
new Product { Id = 2, Name = "Mouse", Price = 25.50m, Date = DateTime.Now.AddDays(-1) }
};
// Simple table output - uses reflection to build columns automatically
products.StringTable().Print(Console.Out);
// Create table options with specific columns
var options = new TableOptions<Product>()
.SetColumn(x => x.Id)
.SetColumn(x => x.Name)
.SetColumn(x => x.Price);
var table = products.StringTable(options);
table.Print(Console.Out);
// Build columns automatically using reflection
var options = new TableOptions<Product>()
.BuildColumnsByReflection()
.Cast<Product>();
// Apply formatting and customization
options.Format(x => x.Price, "C2") // Currency format
.ColumnHeader(x => x.Name, "Product Name") // Custom header
.ColumnOrder(x => x.Date, -1); // Move Date to first position
var table = products.StringTable(options);
table.Print(Console.Out);
// Register table options globally for reuse
var options = new TableOptions<Product>()
.BuildColumnsByReflection()
.Cast<Product>()
.Format(x => x.Price, "C2");
TableOptionFactory.Instance.Register(options);
// Use registered options anywhere in your application
products.StringTable().Print(Console.Out); // Uses registered options automatically
// Dictionary tables
var dict = new Dictionary<string, string> {
{ "Key1", "Value1" },
{ "Key2", "Value2" }
};
dict.StringTable().Print(Console.Out);
// String array tables
var array = new string[] { "Item1", "Item2", "Item3" };
array.StringTable().Print(Console.Out);
// Export as markdown table
var options = new TableOptions<Product>()
.SetColumn(x => x.Id)
.SetColumn(x => x.Name)
.SetColumn(x => x.Price);
using var writer = new StringWriter();
products.MarkdownTable(writer, options);
Console.WriteLine(writer.ToString());
// Output: Id|Name|Price
// -|-|-
// 1|Laptop|999.99
var table = products.StringTable();
// Set minimum width for specific columns
table.MinWidth(col => col.Name == "Name", 15) // Minimum width for Name column
.MinWidth(col => col.Name == "Price", 10) // Minimum width for Price column
.AdjustColumnWidth(80); // Total table width limit
table.Print(Console.Out);
// Right-align numeric columns
table.AlignRight(col => col.Name == "Price", true);
The library is built around a few key concepts:
The generic TableOptions<T> class contains the configuration for transforming type T to string-based tabular data. It defines which columns to display, how to format values, and column ordering.
Key methods:
SetColumn(x => x.Property) - Add a column using a property selectorBuildColumnsByReflection() - Automatically discover all public propertiesCast<T>() - Convert to strongly-typed options for fluent configurationFormat(x => x.Property, "format") - Apply string formatting to columnsColumnHeader(x => x.Property, "Header") - Set custom column headersColumnOrder(x => x.Property, order) - Control column display orderThe TableOptionFactory class provides a thread-safe global registry for reusing table configurations across your application. It automatically creates default configurations when none are registered.
// Register once, use everywhere
TableOptionFactory.Instance.Register(myOptions);
var table = myCollection.StringTable(); // Uses registered options
The StringTable class handles the actual table rendering with features like:
TextWriter outputThe library provides convenient extension methods:
StringTable() - Convert collections to tablesMarkdownTable() - Export as markdown formatPrint() - Output to any TextWriterMinWidth() - Set column minimum widthsAlignRight() - Control column text alignmentAlbatross.Text.Table/
├── StringTable.cs # Core table rendering class
├── StringTableExtensions.cs # Extension methods for collections
├── TableOptions.cs # Configuration classes
├── TableOptionBuilder.cs # Fluent builder for options
├── TableOptionFactory.cs # Global registry for configurations
├── TextOptionBuilderExtensions.cs # Builder helper extensions
├── TableColumnOption.cs # Column-specific configuration
├── TextValue.cs # Text formatting utilities
├── Extensions.cs # General utility extensions
├── Assembly.cs # Assembly information
├── Albatross.Text.Table.csproj # Project file
└── README.md # Project documentation
StringTable - Main table rendering class with width adjustment and formattingTableOptions<T> - Configuration for converting objects to table formatTableOptionFactory - Global registry for table configurationsTextValue - Represents formatted text with display width informationTableColumnOption - Individual column configuration// Collection to table conversion
IEnumerable<T>.StringTable(options?) -> StringTable
IDictionary.StringTable() -> StringTable
// Table output methods
StringTable.Print(TextWriter)
StringTable.AdjustColumnWidth(int)
StringTable.MinWidth(predicate, width)
StringTable.AlignRight(predicate, align?)
// Markdown export
IEnumerable<T>.MarkdownTable(TextWriter, options?)
The project includes comprehensive unit tests in the Albatross.Text.Test project:
# Run all tests
dotnet test
# Run tests with detailed output
dotnet test --verbosity normal
# Run tests for specific framework
dotnet test --framework net8.0
The test project demonstrates various usage patterns:
// Basic table creation (TestStringTable.cs)
var options = new TableOptions<TestClass>()
.SetColumn(x => x.Id)
.SetColumn(x => x.Name)
.SetColumn(x => x.Value);
var table = objects.StringTable(options);
// Reflection-based column building (TestBuildingTableOptions.cs)
var options = new TableOptions<TestClass>()
.BuildColumnsByReflection()
.Cast<TestClass>()
.Format(x => x.Value, "0.00");
// Column width adjustment (TestStringTableColumnAdjustment.cs)
var table = new StringTable(headers);
table.AdjustColumnWidth(80); // Fit in 80 characters
// Dictionary and array tables (TestStringTable.cs)
var dict = new Dictionary<string, string> { {"Key1", "Value1"} };
dict.StringTable().Print(writer);
var array = new string[] { "Value1", "Value2" };
array.StringTable().Print(writer);
Test coverage includes:
We welcome contributions! Please follow these guidelines:
main:
git checkout -b feature/your-feature-name
dotnet test
git commit -m "Add: Brief description of your changes"
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2019 Rushui Guan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Albatross.Text.Table:
| Package | Downloads |
|---|---|
|
Albatross.Text.CliFormat
A library that prints text output based on the runtime format expression |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0-133.main | 28 | 5/30/2026 |
| 9.0.3 | 504 | 1/4/2026 |
| 9.0.2 | 69 | 1/4/2026 |
| 9.0.1 | 98 | 12/10/2025 |
| 9.0.0 | 93 | 11/27/2025 |
| 8.2.1 | 121 | 11/1/2025 |
| 8.2.0 | 102 | 10/22/2025 |
| 8.2.0-87.main | 89 | 10/8/2025 |
| 8.2.0-86.main | 81 | 10/7/2025 |
| 8.2.0-85.main | 79 | 10/5/2025 |
| 8.2.0-80.main | 82 | 10/3/2025 |
| 8.2.0-79.main | 81 | 10/3/2025 |
| 8.1.0-67.main | 96 | 9/10/2025 |
| 8.1.0-64.main | 96 | 9/3/2025 |
| 8.0.11 | 110 | 6/27/2025 |
| 8.0.10 | 89 | 6/26/2025 |
| 8.0.8 | 116 | 4/25/2025 |
| 8.0.7 | 123 | 4/15/2025 |
| 8.0.6 | 141 | 4/9/2025 |