-
Notifications
You must be signed in to change notification settings - Fork 373
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
Consider IParsable
#2385
Comments
Related feature requests dotnet/csharplang#905, dotnet/csharplang#6308 |
I have done some more work on this. The things that define public class ValueResult<T> : ValueResult
{
internal ValueResult(
CliSymbol valueSymbol,
string rawValue,
IEnumerable<Location> locations,
ValueResultOutcome outcome)
: base(valueSymbol, locations, outcome, error)
{
RawValue = rawValue;
var conversionDone = false;
#if NET7_0_OR_GREATER
if (Value is IParsable<T> parseable)
{ This code If someone can solve this, I would love to hear about it. If we can not treat a
|
On further consideration, I like the .NET 6 plus design of requiring either IParsable or a type converter as a type parameter. It leans into IParsable, which I think is a good decision. Where that does not work, we still have a guarantee of having a converter. Down-level and multi-targeting might be a bit messier than needed, but it would provide a good upgrade story. |
ArgumentConverter.StringConverters
defines a dictionary of delegates that perform parsing for specific types. The dictionary approach allows new types to be included, and alternative mechanisms to parsing, such as calling a constructor with a single string parameter.It also requires maintenance of the types in the list.
IParseable<T>
is provided for a long list of types in the .NET libraries, and using it would be an awesome way to provide support for many types. However, it is not clear that we can determine use it - at least I do not have my head around how we can manipulate the generic without reflection.If it is possible to use it, we would need to fall back to not using it in .NET Standard 2.0.
The text was updated successfully, but these errors were encountered: