spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
9.17k stars 472 forks source link

Allow null values in table #1616

Open stephanstapel opened 3 weeks ago

stephanstapel commented 3 weeks ago

Is your feature request related to a problem? Please describe. Currently, Spectre.Console throws an exception if one passes a null value for a table cell value: https://github.com/spectreconsole/spectre.console/blob/2cc6c457ade3c0b795ebb4d0f8868e1befc56a6c/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs#L7

Describe the solution you'd like I propose to get rid of the exception and just assume an empty value (or 'NULL' as an alternative). At least in my environment, I am using Spectre.Console for internal output and am wondering how I would deal with eventual exceptions in my code. Passing a null value is nothing that imho is exceptional, it is just one possible value.


Please upvote :+1: this issue if you are interested in it.

stephanstapel commented 3 weeks ago

I am happy to send in a pull request, just let me know if you want this feature in the component!

patriksvensson commented 3 weeks ago

Sorry, but why would you create a Markup with a null value? The contract says it accepts a string.

Unless you've turned off nullable reference types, you should get a warning when passing something that might be null. I would recommend doing a value ?? string.Empty in these places.

stephanstapel commented 3 weeks ago

I'm passing quite values I am adding like

AddRow(Contact?.Firstname, ....);

it would be convenient not to care about null or not null. I tried ConsoleTableExt which doesn't produce such a nice output but accepts this kind of value.