shibayan / Sharprompt

Interactive command-line based application framework for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Prompt.Input<Guid>

kimsey0 opened this issue · comments

It would be useful to be able to read GUIDs like:

var resourceId = Prompt.Input<Guid>("Please enter resource ID");

However, this fails since Convert.ChangeType can't convert from string to Guid at

public static T ConvertTo(object value) => (T)Convert.ChangeType(value, _underlyingType ?? _targetType);

It might perhaps be implemented by instead using TypeDescriptor.GetConverter(_underlyingType ?? _targetType).ConvertFrom(value) or TypeDescriptor.GetConverter(_underlyingType ?? _targetType).ConvertFromInvariantString(value), which would then delegate to GuidConverter for GUIDs, though the effect on other types, like floating point numbers, would of course have to be considered.

Thank you. This change looks good to me.

It has been improved to v2.3.3. Thank you!

Thank you!