TablerKTU 1.0.0

Makes text tables out of data, used for university labs. 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.

Install-Package TablerKTU -Version 1.0.0
dotnet add package TablerKTU --version 1.0.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TablerKTU, 1.0.0"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

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!.

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!.

Release Notes

Initial release

Dependencies

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 History

Version Downloads Last updated
1.0.0 598 5/5/2018