-
Notifications
You must be signed in to change notification settings - Fork 73
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
Make Option<T>.ToString return string value of Some or blank #17
Comments
Hi, I think consistency with nullable is a good idea, and a very reasonable expectation (in retrospect, it seems like the obvious thing to do). I consider the suggestion approved. It is, however, a breaking change, so I will designate this for version 4.0.0. Thanks a lot for the input! |
This renders Option<T>.ToString() consistent with Nullable<T>.ToString() and easier to substitute for. Closes nlkl#17
Hi @nlkl |
Option<T>.ToString()
is currently implemented to return a string representation ofOption<T>
's state when ideally it should simply return a blank whenNone
orSome(null)
and the string representation of the value ofSome
otherwise. In other words:Doing so will go a long way to help
Option<T>
to be easily substituted in code forNullable<T>
and references where one desires. The trouble with the current implementation is that any refactoring towardsOption<T>
will require one to thoroughly review all code where string formatting is used. For example, suppose the following code:This prints:
However, if you use
Option<T>
instead:then output changes to (depending on the thread's default culture) something along the lines of:
If you have unit tests then you can catch this sort of issue otherwise your luck will be your friend or your enemy. Either way, the fix looks ugly:
For debugging purposes, one can still rely on
DebuggerDisplayAttribute
to display the string representation as it is today.The text was updated successfully, but these errors were encountered: