-
Notifications
You must be signed in to change notification settings - Fork 33
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
Unintuitive ValueObject
behavior
#5
Comments
So how about implementing If Regarding the constructor,
|
Okay. I can propose a PR with something like that. But is there any value to having Relatedly, there is an |
Agreed, internal it should be. Sounds to me like IsOfTypeInt and IsOfTypeString should be mutually exclusive. Have a look at the Match method in LeafPattern.— On Wed, Dec 18, 2013 at 6:02 PM, Kyle Peter Fritz
|
Yeah, clearly |
Thanks for the PR @kyle-fritz-zocdoc! I think the first interpretation ( I will push a release with your changes soon. |
Fix released as part of 0.6.1.5. |
ValueObject
, the object that is returned fromDocopt.Apply()
has some unintuitive behavior in its type checking properties. This class is a wrapper around anobject
that was parsed from the user args. Helpfully, theValueObject
contract has several properties that allow one to check the type of the argument token:IsList
,IsString
,IsInt
.My main issue is with the
IsInt
property. As far as I can tell, it is never true, even when integer arguments are supplied. That's because theIsInt
property is implemented by doing a type check with theis
keyword on the object with which theValueObject
is constructed. However, theValueObject
is constructed with thestring
-typed token. While something like that might work in python, it will fail consistently in .NET. This results in a weird situation where objects that haveIsInt
=false
have proper values for theirAsInt
properties.There's a couple ways one could fix this. Changing the
IsInt
property to return the result of a call toInt32.TryParse()
would work. Alternatively, the code that instantiatesValueObject
could attempt to convert the string prior to invoking the constructor.I may be off-base here if the
IsInt
property was never meant to be used be consumers of this library. If that is the case and this property is behaving in this way purposely, may I ask that we make itinternal
instead ofpublic
?The text was updated successfully, but these errors were encountered: