/// <summary> /// Initializes a new instance of the <see cref="CommandLineSwitch"/> class /// </summary> /// <param name="instance">Instance we're configuring with this switch.</param> /// <param name="method">Method to invoke if this switch is present.</param> public CommandLineSwitch(object instance, MethodInfo method) : base(method) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } Debug.Assert(method.DeclaringType != null); if (!method.DeclaringType.GetTypeInfo().IsInstanceOfType(instance)) { throw new ArgumentException("Expect method to be callable on instance", nameof(method)); } _instance = instance; _method = method; ShortName = "-" + CamelCase.ToShortName(method.Name); AlternateShortName = "/" + CamelCase.ToShortName(method.Name); LongName = "--" + CamelCase.ToDashedName(method.Name); }
/// <summary> /// Initializes a new instance of the <see cref="CommandLineParameter{V}"/> class /// </summary> /// <param name="instance">Instance that we're configuring with this parameter.</param> /// <param name="method">Method to invoke if this parameter is used.</param> public CommandLineParameter(object instance, MethodInfo method) : base(method) { _instance = instance ?? throw new ArgumentNullException(nameof(instance)); Debug.Assert(method.DeclaringType != null); if (!method.DeclaringType.GetTypeInfo().IsInstanceOfType(instance)) { throw new ArgumentException( "Expect method to be callable on instance", nameof(method)); } _method = method; _parameterInfo = method.GetParameters().Single(); var name = method.Name; ShortName = "-" + CamelCase.ToShortName(name); AlternateShortName = "/" + CamelCase.ToShortName(name); LongName = "--" + CamelCase.ToDashedName(name); IsRequired = method.GetCustomAttribute <RequiredAttribute>() != null; IsMultivalued = _parameterInfo.ParameterType.IsIEnumerable(); }