ZimLabs.TableCreator
2.1.1
dotnet add package ZimLabs.TableCreator --version 2.1.1
NuGet\Install-Package ZimLabs.TableCreator -Version 2.1.1
<PackageReference Include="ZimLabs.TableCreator" Version="2.1.1" />
paket add ZimLabs.TableCreator --version 2.1.1
#r "nuget: ZimLabs.TableCreator, 2.1.1"
// Install ZimLabs.TableCreator as a Cake Addin #addin nuget:?package=ZimLabs.TableCreator&version=2.1.1 // Install ZimLabs.TableCreator as a Cake Tool #tool nuget:?package=ZimLabs.TableCreator&version=2.1.1
ZimLabs.TableCreator
This library is not very special 😃 It takes a list of objects and creates an ASCII "table", markdown table or a CSV list. Very simple and straight forward.
Content
Install
PM > Install-Package ZimLabs.TableCreator
Usage
Attributes:
internal sealed class Person
{
[Appearance(TextAlign = TextAlign.Right, Order = 1)]
public int Id { get; set; }
[Appearance(Name = "First name", Order = 3)]
public string Name { get; set; }
[Appearance(Order = 2)]
public string LastName { get; set; }
[Appearance(Name = "E-Mail", Order = 4)]
public string Mail { get; set; }
[Appearance(Ignore = true)]
public string Gender { get; set; }
[Appearance(Name = "Job title")]
public string JobTitle { get; set; }
[Appearance(Format = "yyyy-MM-dd")]
public DateTime Birthday { get; set; }
}
Note: If not all properties have an Order value, the following order is applied:
- occurrence in the class
- order according to Order value
Usage of the Create / Save methods:
var personList = CreateDummyList().ToList();
// Print the complete list
Console.WriteLine("Person List");
Console.WriteLine(personList.CreateTable());
// Save the person list
personList.SaveTable("PersonList.txt");
// Print a single person
var person = personList.FirstOrDefault();
Console.WriteLine("Single person");
Console.WriteLine("Value list");
Console.WriteLine(person.CreateValueList());
Console.WriteLine("Value table");
Console.WriteLine(person.CreateValueTable());
// Save the person (as value list)
person.SaveValue("FileName.txt");
// Save the person (as table)
person.SaveValueAsTable("FileName.txt");
Console.WriteLine("Done");
Console.ReadLine();
The result:
Person List
+-------------------------------+------------+----+-------------+------------+-------------------------------+
| Job title | Birthday | Id | LastName | First name | E-Mail |
+-------------------------------+------------+----+-------------+------------+-------------------------------+
| Environmental Tech | 1968-03-26 | 1 | Giblin | Tommy | tgiblin0@amazon.co.uk |
| Teacher | 1952-04-24 | 2 | Puden | Sven | spuden1@soundcloud.com |
| VP Quality Control | 1965-04-10 | 3 | Czaple | Garvy | gczaple2@com.com |
| Pharmacist | 1986-07-23 | 4 | Mariotte | Eryn | emariotte3@issuu.com |
| Senior Financial Analyst | 1967-11-09 | 5 | Oiseau | Zaccaria | zoiseau4@huffingtonpost.com |
+-------------------------------+------------+----+-------------+------------+-------------------------------+
Single person
Value list
- Job title.: Environmental Tech
- Birthday..: 26/03/1968 00:00:00
- Id........: 1
- LastName..: Giblin
- First name: Tommy
- E-Mail....: tgiblin0@amazon.co.uk
Value table
+------------+-----------------------+
| Key | Value |
+------------+-----------------------+
| Job title | Environmental Tech |
| Birthday | 26/03/1968 00:00:00 |
| Id | 1 |
| LastName | Giblin |
| First name | Tommy |
| E-Mail | tgiblin0@amazon.co.uk |
+------------+-----------------------+
For more examples take a look at the demo project.
Known issues
Currently it's possible to call the methods for a single entry with a list:
// Wrong call
personList.CreateValueList();
I'll try to fix the bug in the next version (1.5).
Since I didn't find a solution to prevent calling the method for a single value, I included a check that throws an error when trying to call the method for a single value from a list.
If you call from a list a function, which was developed only for a single value, an NotSupportedException
with the following message will be thrown:
The specified type is not supported by this method. Please choose "CreateTable" or "SaveTable" instead.
Sorry for the inconvenience.
Changelog
Version 2.1.1
- Option
addHeader
addded, with which you can decide whether the CSV content should contain a header line. - Added classes for the various options to improve clarity (
TableCreateOptions
andTableCreatorListOptions
). - Appearance attribute adjusted. It is now possible to specify whether the content of a property should be encapsulate in quotation marks.
Version 2.1.0
- Fixed some bugs:
- Custom format was not used in some cases (
DataTable
functions) - Missing
null
check in the list functions
- Custom format was not used in some cases (
- Added .NET 8 support (multiple target frameworks). Now .NET 7 and .NET 8 are supported
- Minor changes under the hood (usage of the new C# 12 features)
Version 2.0.2
- Added missing api documentation
Version 2.0.1
- Fixed a bug in the
DataTable
CSV generator
Version 2.0.0
🚨🚨🚨 BREAKING CHANGE 🚨🚨🚨
Between the last version and this one the runtime environment has been changed! New runtime environment is .NET 7
Other changes:
- Added the support of
DataTable
Version 1.5.0
Added check function to the following methods
CreateValueTable
SaveValue
SaveValueAsTable
The function checks if the given value is a list or not. If the value is a list an exception (NotSupportedException
) will be thrown.
For more information see Known issues.
I also removed the documentation for the classes, because the tool I use for that doesn't seem to cope with .NET Standard, so the documentation wasn't updated anymore.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.1.1 | 587 | 2/25/2024 | |
2.1.0 | 203 | 12/15/2023 | |
2.0.2 | 240 | 9/15/2023 | |
2.0.1 | 318 | 4/27/2023 | |
2.0.0 | 207 | 4/27/2023 | |
1.5.0 | 559 | 3/19/2023 | |
1.4.1 | 351 | 2/5/2023 | |
1.4.0 | 275 | 2/5/2023 | |
1.3.1 | 6,518 | 1/21/2022 | |
1.3.0 | 504 | 1/19/2022 | |
1.2.4 | 320 | 12/29/2021 | |
1.2.3 | 332 | 12/29/2021 | |
1.2.2 | 351 | 12/29/2021 | |
1.2.1 | 384 | 10/29/2021 | |
1.2.0 | 452 | 5/8/2021 | |
1.1.2 | 372 | 5/8/2021 | |
1.1.1 | 452 | 12/23/2020 | |
1.1.0 | 438 | 12/11/2020 | |
1.0.1 | 435 | 11/19/2020 | |
1.0.0 | 639 | 10/31/2020 |
Added new options for the CSV export. For more information see the readme