Пример #1
0
#pragma warning disable RECS0021 // Warns about calls to virtual member functions occuring in the constructor

        public Options(OptionsContext context)
        {
            Context = context;
            InitializeOtherDefaults();
            OptionParser = new OptionList(this, context);
            OptionParser.AdditionalBannerInfo = AdditionalBannerInfo;
        }
        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);
        }
 public HelpCommand(List <ICommand> commands, OptionList optionParser, OptionsContext context)
 {
     _commands     = commands;
     _optionParser = optionParser;
     _context      = context;
 }