Giter Site home page Giter Site logo

Comments (5)

nohwnd avatar nohwnd commented on July 20, 2024 2

@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.

from commandlineutils.

natemcmaster avatar natemcmaster commented on July 20, 2024

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.

from commandlineutils.

natemcmaster avatar natemcmaster commented on July 20, 2024

@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.

from commandlineutils.

stale avatar stale commented on July 20, 2024

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.

from commandlineutils.

natemcmaster avatar natemcmaster commented on July 20, 2024

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

from commandlineutils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.