Skip to content

Commit 8881713

Browse files
committed
2 parents 9351573 + 8633808 commit 8881713

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ Columnames can be prefixed and suffixed with:
6969

7070
When a columnname is specified as `"^Salary"`, the column name will be right aligned, the values will default to left. When the name is specified as `"Salary^"` the column values will be right aligned, the column name itself will default to left aligned. And, finally, when the name is specified as `"^Salary^"` then both the column name and values will be right aligned.
7171

72-
If you want more control over a column you'll need to use the `AddColumn()` method which allows you to specify a minimum width for the column as well as a `TypeHandler` (see [Type Handling](#type-handling)).
72+
If you want more control over a column you'll need to use the `AddColumn()` method which allows you to specify a minimum / fixed width for the column as well as a `TypeHandler` (see [Type Handling](#type-handling)).
7373

7474
## Column widths
7575

76-
A column, by default, simply stretches to be wide enough to contain all values in that column. You can, however, specify a minimum width (`MinWidth`) or a width (`Width`). The `MinWidth` ensures the column is always at least the number of specified characters wide, but may be less wide when the column only contains values of less length. The `Width` ensures a column is always exactly the specified width. Longer values will be truncated. Note that truncating depends on the alignment of the values. Right-aligned values will be truncated from the left, left-aligned values will be truncated from the right and center-aligned values will be truncated from both sides.
76+
A column, by default, simply stretches to be wide enough to contain all values in that column. You can, however, specify a minimum width (`MinWidth`) or a width (`Width`). The `MinWidth` ensures the column is always at least the number of specified characters wide, but may be wider when the column contains longer values. The `Width` ensures a column is always exactly the specified width. Longer values will be truncated. Note that truncating depends on the alignment of the values. Right-aligned values will be truncated from the left, left-aligned values will be truncated from the right and center-aligned values will be truncated from both sides.
7777

7878
To specifiy a width, use either the `AddColumn()` overload that allows you to pass an optional `minWidth` or `width` argument, or the `AddColumn(Column)` overload and specify the `width` or `minWidth` with the `Column`'s constructor arguments.
7979

@@ -118,9 +118,7 @@ So when we then specify our values as decimals (by adding the `m`-suffix)...
118118
var table = new Table();
119119
table.AddColumns(new[] { "No.", "Name", "Position", "^Salary^" })
120120
.AddRow(1, "Bill Gates", "Founder Microsoft", 10000m)
121-
.AddRow(2, "Steve Jobs", "Founder Apple", 1200000m)
122-
.AddRow(3, "Larry Page", "Founder Google", 1100000m)
123-
.AddRow(4, "Mark Zuckerberg", "Founder Facebook", 1300000m);
121+
// etc ...
124122
```
125123

126124
...and we register our new `CurrencyTypeHandler`...
@@ -136,10 +134,10 @@ Console.WriteLine(tablebuilder.Build(table, new CultureInfo("en_US")));
136134
```cmd
137135
No. | Name | Position | Salary
138136
--- | --------------- | ----------------- | --------------
139-
1 | Bill Gates | Founder Microsoft | $ 10.000,00
140-
2 | Steve Jobs | Founder Apple | $ 1.200.000,00
141-
3 | Larry Page | Founder Google | $ 1.100.000,00
142-
4 | Mark Zuckerberg | Founder Facebook | $ 1.300.000,00
137+
1 | Bill Gates | Founder Microsoft | $ 10,000.00
138+
2 | Steve Jobs | Founder Apple | $ 1,200,000.00
139+
3 | Larry Page | Founder Google | $ 1,100,000.00
140+
4 | Mark Zuckerberg | Founder Facebook | $ 1,300,000.00
143141
```
144142

145143
An alternative method of creating a `TypeHandler` is to inherit from `DelegatingTypeHandler<T>` which allows you to simply use a delegate function:
@@ -170,6 +168,8 @@ And for those about to point out this can be written even shorter:
170168
tablebuilder.TypeHandlers.AddHandler<decimal>((v, _) => $"$ {v:N2}");
171169
```
172170

171+
A `TypeHandler` can also be passed to a `Column`'s constructor, in which case that `TypeHandler` is used for all values in that column.
172+
173173
### Null value handling
174174

175175
A special case is the `NullValueHandler`; by default a `null` value is formatted as an empty string. However, you may want to show `null` values as "`<NULL>`" for example. To accomplish this we simply use the built-in `NullValueHandler`:
@@ -190,9 +190,7 @@ public record Person(string Name, string Position, decimal Salary);
190190
var persons = new[]
191191
{
192192
new Person("Bill Gates", "Founder Microsoft", 10000m),
193-
new Person("Steve Jobs", "Founder Apple", 1200000m),
194-
new Person("Larry Page", "Founder Google", 1100000m),
195-
new Person("Mark Zuckerberg", "Founder Facebook", 1300000m),
193+
// etc ...
196194
};
197195
```
198196
#### Default object handling
@@ -245,10 +243,10 @@ Which outputs:
245243
```cmd
246244
Name | Position | Salary
247245
--------------- | ----------------- | ------------
248-
Bill Gates | Founder Microsoft | 10.000,00
249-
Steve Jobs | Founder Apple | 1.200.000,00
250-
Larry Page | Founder Google | 1.100.000,00
251-
Mark Zuckerberg | Founder Facebook | 1.300.000,00
246+
Bill Gates | Founder Microsoft | 10,000.00
247+
Steve Jobs | Founder Apple | 1,200,000.00
248+
Larry Page | Founder Google | 1,100,000.00
249+
Mark Zuckerberg | Founder Facebook | 1,300,000.00
252250
```
253251

254252
TextTableBuilder will still use the `TypeHandler`s to handle the types of the values as always.
@@ -312,9 +310,7 @@ If we now print the table:
312310
var persons = new[]
313311
{
314312
new Person("Bill Gates", "Founder Microsoft", 10000m, new DateTime(1955, 10, 28)),
315-
new Person("Steve Jobs", "Founder Apple", 1200000m, new DateTime(1955, 2, 24)),
316-
new Person("Larry Page", "Founder Google", 1100000m, new DateTime(1973, 3, 26)),
317-
new Person("Mark Zuckerberg", "Founder Facebook", 1300000m, new DateTime(1984, 3, 14)),
313+
// etc ...
318314
};
319315

320316
var table = new Table();

0 commit comments

Comments
 (0)