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

Add support for TypeConverter #62

Closed
natemcmaster opened this issue Mar 15, 2018 · 5 comments · Fixed by #345
Closed

Add support for TypeConverter #62

natemcmaster opened this issue Mar 15, 2018 · 5 comments · Fixed by #345
Labels
enhancement help wanted We would be willing to take a well-written PR to help fix this.
Milestone

Comments

@natemcmaster
Copy link
Owner

Followup to #59

We should

  1. Add a TypeConverterParserAdapter. Implements IValueParser and takes an instance of TypeConverter.
  2. Update ValueParserProvider to fallback to TypeConverterAttribute when present and return a TypeConverterParserAdapter.

As a bonus, we could either

  • Update OptionAttributeConvention/ArgumentConvention to honor TypeConverterAttribute
  • or, update those conventions to make it possible to override how the IValueParser is provided.
@natemcmaster natemcmaster added the help wanted We would be willing to take a well-written PR to help fix this. label Mar 26, 2018
@natemcmaster natemcmaster modified the milestones: Future, Backlog Apr 21, 2018
@natemcmaster
Copy link
Owner Author

Putting into the backlog for now as I don't plan to implement it myself. If someone stumbles upon this and wants to implement it, let me know. I'd accept a PR to add this.

@natemcmaster natemcmaster removed this from the Backlog milestone Sep 28, 2018
@nohwnd
Copy link

nohwnd commented Nov 14, 2018

@natemcmaster @rubenprins I looked into this, and read #59 and #51, I'd like to confirm what to do before I start implementing it.

From what I gathered from here :

The main reason is to have the possibility to override how a string is parsed to the target type by putting annotations on option properties. That way we could have:

[Option]
[TypeConverter(typeof(ChmodConverter))]
public int Permissions { get; set; } 

[Option]
public int Count { get; set;}

That would parse each property differently even though the have the same target type:

prg.exe --Permissions "-rwxr-----" --Count 21
Permissions = 740
Count = 21

(Sorry if I misinterpreted the original example, I am not 100% sure what octal chmod is, and this was the only case where it made sense to me:) )

The problem here is parsing the same type two ways does not fit with the api of ParserProvider. Parser provider chooses the parser based on the type of the data, not based on the property. For example this snippet from OptionAttributeConventionBase:

case CommandOptionType.SingleValue:
var parser = context.Application.ValueParsers.GetParser(prop.PropertyType);

I assume we cannot change how the ParserProvider works, so should I add a layer over it? It would select the TypeConverter from attribute if present, and fallback to TypeConverter when ParserProvider returns null.

@natemcmaster
Copy link
Owner Author

@nohwnd you are correct. There are two pieces of work here: allowing property-specific parser settings, and honoring TypeConverterAttribute as the way to set property-specific parsers. I think both should be possible without breaking existing API.

@stale
Copy link

stale bot commented Feb 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 7 days.

@stale stale bot added the closed-wontfix This issue is closed because there are no plans to fix this. label Feb 22, 2019
@stale stale bot closed this as completed Mar 1, 2019
@natemcmaster natemcmaster added closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. and removed closed-wontfix This issue is closed because there are no plans to fix this. labels May 17, 2019
@natemcmaster natemcmaster reopened this Feb 18, 2020
@stale stale bot removed the closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. label Feb 18, 2020
@natemcmaster natemcmaster added this to the 3.0 milestone Feb 18, 2020
@natemcmaster
Copy link
Owner Author

Partially addressed in #345. Need to add tests that validate this works as expected.

@natemcmaster natemcmaster linked a pull request Feb 18, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted We would be willing to take a well-written PR to help fix this.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants