Skip to content

Cannot pass "true" or "false" to a string option #88

@ericnewton76

Description

@ericnewton76

Issue by ptylenda
Tuesday Sep 20, 2016 at 11:30 GMT
Originally opened as gsscoder/commandline#353


Define a string option:

[Option('e', "engineering", SetName = "console", Required = false, HelpText = "Flag whether the build is engineering build", ")]
        public string Engineering { get; set; }

It is intended to support not only "true" and "false" values and therefore is not boolean (and also not an enum, because it gives us less flexibility)

When you call the executable with "-e true", you receive:

Unhandled Exception: System.ArgumentException: Object of type 'System.Boolean' c
annot be converted to type 'System.String'.
   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo
culture, Boolean needsSpecialCast)
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo cul
ture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder bi
nder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, Bindi
ngFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, O
bject[] index)
   at CommandLine.Core.ReflectionExtensions.SetValue[T](PropertyInfo property, T
 instance, Object value)
   at CommandLine.Core.ReflectionExtensions.<>c__DisplayClass6_0`1.<SetPropertie
s>b__0(T current, SpecificationProperty specProp)
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source
, TAccumulate seed, Func`3 func)
   at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_2`1.<Build>b__15()
   at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_0`1.<Build>b__7()
   at CommandLine.Parser.ParseArguments[T](IEnumerable`1 args)

I think it should be possible to assign ANY text value to a string object, it should not be limited by automatic type recognition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions