private void ApplyCommandLineOptions(IEnumerable <ParsedOption> options) { var positionalArgumentIndex = 0; foreach (var option in options) { if (option.Definition == null) { if (positionalArgumentIndex < IndexedPositionalArgumentActions.Count) { IndexedPositionalArgumentActions[positionalArgumentIndex](option.Argument); } else { AdditionalPositionalArgumentAction(option.Argument); } ++positionalArgumentIndex; } else { OptionActions[option.Definition](option.Argument); } } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (!ready) return; _active = activeCB.SelectedItem.ToString(); _action = OptionActions.Update; this.Close(); }
public OptionsForm(List<string> Groups, string ActiveGroup) { _action = OptionActions.Nothing; _groups = Groups; _active = ActiveGroup; InitializeComponent(); }
private void ApplyAttribute(ICommandLineOptions commandLineOptions, PropertyInfo property, OptionAttribute optionAttribute) { var optionDefinition = new OptionDefinition { LongName = optionAttribute.LongName, ShortName = optionAttribute.ShortName, Argument = optionAttribute.Argument }; if (optionDefinition.Argument == OptionArgument.None) { // If the option takes no arguments, it must be applied to a boolean property. if (property.PropertyType != typeof(bool)) { throw new InvalidOperationException($"OptionAttribute {optionDefinition.Name ?? ""} with no Argument may only be applied to a boolean property."); } // If the option is specified, set the property to true. OptionActions.Add(optionDefinition, _ => property.SetOptionProperty(commandLineOptions, true)); } else { // If the option takes an argument, then attempt to parse it to the correct type. var parser = GetParser(property.PropertyType, CreateConverter(optionAttribute.Converter)); OptionActions.Add(optionDefinition, parameter => { if (parameter == null) { return; } var value = Convert(parser, parameter, property.PropertyType); property.SetOptionProperty(commandLineOptions, value); }); } }
private void ApplyAttribute(ICommandLineOptions commandLineOptions, PropertyInfo property, OptionPresentAttribute optionPresentAttribute) { // This attribute must be applied to a boolean property. if (property.PropertyType != typeof(bool)) { throw new InvalidOperationException($"{nameof(OptionPresentAttribute)} may only be applied to a boolean property."); } var optionDefinition = optionPresentAttribute.LongName != null? OptionActions.FirstOrDefault(x => StringComparer.Equals(x.Key.LongName, optionPresentAttribute.LongName)).Key: OptionActions.FirstOrDefault(x => StringComparer.Equals(x.Key.ShortNameAsString, optionPresentAttribute.ShortNameAsString)).Key; if (optionDefinition == null) { throw new InvalidOperationException($"{nameof(OptionPresentAttribute)} does not refer to an existing {nameof(OptionAttribute)} for option {optionPresentAttribute.Name}."); } // If the option is specified, set the property to true. OptionActions[optionDefinition] = (Action <string>)Delegate.Combine(OptionActions[optionDefinition], (Action <string>)(_ => property.SetOptionProperty(commandLineOptions, true))); }
private void returnButton_Click(object sender, EventArgs e) { _action = OptionActions.Nothing; this.Close(); }
private void exitButton_Click(object sender, EventArgs e) { _action = OptionActions.Exit; this.Close(); }