Closed oshustov closed 3 years ago
Hey, finally got time to review this.
The TypeDescriptor
approach looks scary indeed. How about we instead extend CommandParameterAttribute
/CommandOptionAttribute
to accept an optional Type? ConverterType
? This way the user can control conversion on per-type basis. For now, let's not bother with a global configuration for this.
Using the standard base converter type is probably not required, as it's unlikely that some existing conversion will be useful in our scenarios. What do you think?
Hey, thanks for the review. You are right, that approach was the next thing I thought about. I going to implement it and create a new PR instead of this one.
Closing in favor of #81
Here is implementation via built in
System.ComponentModel.TypeConverter
andSystem.ComponentModel.TypeDescriptor
types.User have to define type and simple converter for it:
Then bind the converter to the type via
CliApplicationBuilder
:Pros: -validation support -simple in implementation -flexible (user can inherit directly from TypeConverter, but it can be difficult and maybe dangerous) -no custom attributes or other settings required
Cons: -using of the built in type (which adds an attribute in runtime) potentionaly might make some issues with other stuff which are using also this mechanism to convert object types
Closes #41