-
Notifications
You must be signed in to change notification settings - Fork 0
StartOptionAttribute
Lunar Doggo edited this page Jun 5, 2022
·
5 revisions
StartOptionAttribute is an attribute you can use to decorate constructor parameters with in order to define a StartOption
for your application. This attribute only is useful if you use the command-based approach in combination with a CommandApplication. With this attribute you can only create start options associated with a StartOptionGroup.
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class StartOptionAttribute : Attribute
public StartOptionAttribute(string longName, string shortName)
Sitnature | Description | Default |
---|---|---|
public StartOptionValueType ValueType { get; set; } |
Gets or sets the type of the StartOption (Switch, Single, Multiple) | Switch |
public string Description { get; set; } |
Gets or sets the description of the StartOption | String.Empty |
public Type ParserType { get; set; } |
Gets or sets the type of IStartOptionValueParser the StartOption should use | null |
public bool Mandatory { get; set; } |
Gets or sets whether this StartOption has to be set or not | false |
public string ShortName { get; } |
Gets the short name of the StartOption | - |
public string LongName { get; } |
Gets the long name of the StartOption | - |
public class BasicMockCommand : IApplicationCommand
{
private readonly double firstNumber, secondNumber;
private readonly CalculationOperation operation;
private readonly bool verbose;
[StartOptionGroup("calculate", "c", Description = "Executes a calculation")]
public BasicMockCommand([StartOption("number1", "n1", Description = "First number of the calculation", Mandatory = true, ValueType = StartOptionValueType.Single, ParserType = typeof(DoubleOptionValueParser))]double firstNumber,
[StartOption("number2", "n2", Description = "Second number of the calculation", Mandatory = true, ValueType = StartOptionValueType.Single, ParserType = typeof(DoubleOptionValueParser))]double secondNumber,
[StartOption("operation", "o", Description = "Operation to execute", Mandatory = true, ValueType = StartOptionValueType.Single, ParserType = typeof(CalculationOperationValueParser))] CalculationOperation operation,
[GrouplessStartOptionAttribute("verbose", "vb", Description = "Enable verbose output")]bool verbose)
{
this.secondNumber = secondNumber;
this.firstNumber = firstNumber;
this.operation = operation;
this.verbose = verbose;
}
...
}