public OptionList(object optionBundle, OptionsContext context, bool stopOnFirstNonOption = false) { if (optionBundle == null) { throw new ArgumentNullException(nameof(optionBundle)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } Type optionsType = optionBundle.GetType(); _optionBundle = optionBundle; _context = context; _stopOnFirstNonOption = stopOnFirstNonOption; _assemblyInfo = AssemblyInformation.FromEntryAssembly.WithDefaults; foreach (MemberInfo mi in optionsType.GetMembers()) { object[] attribs = mi.GetCustomAttributes(typeof(KillInheritedOptionAttribute), true); if (attribs == null || attribs.Length == 0) { attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true); if (attribs != null && attribs.Length > 0) { var option = new OptionDetails(mi, (OptionAttribute)attribs[0], optionBundle, _context.ParsingMode, false); _list.Add(option); _hasSecondLevelHelp = _hasSecondLevelHelp || option.SecondLevelHelp; } else if (mi.DeclaringType == mi.ReflectedType) // not inherited { attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true); if (attribs != null && attribs.Length > 0) { AddArgumentProcessor(mi); } } } } if (_argumentProcessor == null) // try to find an inherited one { foreach (MemberInfo mi in optionsType.GetMembers()) { if (mi.DeclaringType != mi.ReflectedType) // inherited { object[] attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true); if (attribs != null && attribs.Length > 0) { AddArgumentProcessor(mi); } } } } _list.Sort(); OptionDetails.LinkAlternatesInsideList(_list); }
bool IsAlternate(string compoundArg) { OptionDetails next = NextAlternate; while (next != null) { if (next.IsThisOption(compoundArg)) { return(true); } next = next.NextAlternate; } return(false); }