TablerKTU 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package TablerKTU --version 1.0.0
NuGet\Install-Package TablerKTU -Version 1.0.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="TablerKTU" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TablerKTU --version 1.0.0
#r "nuget: TablerKTU, 1.0.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 TablerKTU as a Cake Addin
#addin nuget:?package=TablerKTU&version=1.0.0

// Install TablerKTU as a Cake Tool
#tool nuget:?package=TablerKTU&version=1.0.0

Tabler

Makes text tables out of data, used for university lab projects. In our university most of the tasks require that you print out both the input data and the results in tables, Tabler is a utility to help out with that chore.

Example

Consider a data class:

class DataClass
    {
        public string Field = "Hello world!";
        public float Prop2 { get; private set; } = 5;
        public float Prop { get; set; } = 10;
    }

To print it to a file or the console, call the TextTableBuilder, add an object and print to a stream:

var dataObject = new DataClass();

using (var sw = new StreamWriter(Console.OpenStandardOutput()))
    new TextTableBuilder<DataClass>()
        .AddObject(dataObject)
        .Print(sw);

The resulting output will look something like this:

-------------------------
|       Field|Prop|Prop2|
-------------------------
|Hello world!|   5|   10|
-------------------------

Lists are also accepted:


List<DataClass> dataList = new List<DataClass>();
dataList.Add(new DataClass());
dataList.Add(new DataClass());
dataList.Add(new DataClass());

using (var sw = new StreamWriter("output.txt"))
    new TextTableBuilder<DataClass>()
        .AddObjects(dataList)
        .Print(sw);

Headers

By default, TextTableBuilder uses reflection to grab the properties and fields of the class it is given and uses their names as the default headers in the tables it prints. However, the user can also define their own header names as well. At present, there are three ways of accomplishing this.

Passing a sequence of strings:


// Using individual strings
using (var sw = new StreamWriter("output.txt"))
new TextTableBuilder<DataClass>()
                .AddObject(d) 
                .AddObjects(list)
                .SetHeaders("Test1", "Test2", "Test3") // The number of elements must match the number of columns!
                .Print(sw);
                
// Using a string array
string[] headers = new String[] { "Test1", "Test2", "Test3" };

using (var sw = new StreamWriter("output.txt"))
new TextTableBuilder<DataClass>()
                .AddObject(d) 
                .AddObjects(list)
                .SetHeaders(headers) // The number of elements in the array must match the number of columns!
                .Print(sw);

The output would look like this:

--------------------------
|       Test1|Test2|Test3|
--------------------------
|Hello world!|    5|   10|
--------------------------

The other way of doing this is by using Lambda expressions and referencing which properties' names to change:

using (var sw = new StreamWriter("output.txt"))
new TextTableBuilder<DataClass>()
                .AddObjects(somelist)
                .SetHeader(f => f.Prop2, "ChangedHeader")
                .Print(sw);

And the result would be:

---------------------------------
|       Field|Prop|ChangedHeader|
---------------------------------
|Hello world!|   5|           10|
---------------------------------

Lastly, you can avoid having to set custom headers later by giving your properties and fields attributes in the data class itself, like so:

    public class DataClass
    {
        [TableColumn("Some header here")]
        public string TestField = "Hello world!";

        [TableColumn("Another header over there")]
        public float TestProp2VeryLongName_Is_Still_Not_cool { get; private set; } = 5;

        [TableColumn("Sick new header fam!!!")]
        public float TestProp { get; set; } = 10;
    }

And these new headers will reflect in whatever you print:

Use with ASP.NET Tables and GridViews

Fortunately, the process is almost identical as to the one before, but now we pass a reference to a Table or a GridView object, instead of a stream.

An example with the same test class, by using an ASP Table:

var dataObject = new DataClass();
// This time we don't create a StreamWriter of any kind
    new TextTableBuilder<DataClass>()
        .AddObject(dataObject)
        .Print(testTable); // Instead, we pass a reference to the ASP Table here.

The process is the same when working with GridViews as well!

var dataObject = new DataClass();
    new TextTableBuilder<DataClass>()
        .AddObject(dataObject)
        .Print(testGridView); // Now, we pass a reference to a GridView!.
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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

Initial release