Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null values in table #1616

Open
stephanstapel opened this issue Aug 22, 2024 · 4 comments
Open

Allow null values in table #1616

stephanstapel opened this issue Aug 22, 2024 · 4 comments

Comments

@stephanstapel
Copy link

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:

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 👍 this issue if you are interested in it.

@stephanstapel
Copy link
Author

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

@patriksvensson
Copy link
Contributor

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
Copy link
Author

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.

@bothzoli
Copy link

You can do this too to not need to care about null/not null:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

3 participants