-
-
Notifications
You must be signed in to change notification settings - Fork 589
Open
Labels
Description
I want to get AbsoluteUri or null but it's not supported by TextPrompt even with AllowEmpty=true.
var uri = await new TextPrompt<Uri?>( $"abc" )
.AllowEmpty()
.Validate( value =>
{
if ( !( value?.IsAbsoluteUri ?? true ) )
return ValidationResult.Error( "[red]It must be absolute url[/]" );
return ValidationResult.Success();
} )
.ShowAsync( AnsiConsole.Console, CancellationToken.None );
If I press enter then I get "Invalid input".
I suppose that input is string.Empty when we call TryConvertFromString.
UriConverter allow to convert from string.Empty and return null.
In that case condition in line 146 in TextPrompt should be modified and allow result to be null if conversion was successfull.
else if (!TypeConverterHelper.TryConvertFromString<T>(input, out result) || result == null && Nullable.GetUnderlyingType(typeof(T)) == null)
//or maybe
else if (!TypeConverterHelper.TryConvertFromString<T>(input, out result))
This issue could happen for other types if allow to convert from string.Empty and return null.
What do you think?
Please upvote 👍 this issue if you are interested in it.
pleonex, OculiViridi and BernhardNinaus
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo 🕑