예제 #1
0
        private void Initialize()
        {
            commandInfos = new List <CommandInfo>();
            properties   = new List <ParameterInfo>();

            foreach (var propertyInfo in ArgumentType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var attributes = propertyInfo.GetCustomAttributes <CommandLineAttribute>(true).ToArray();
                if (attributes.Any())
                {
                    var parameterInfo = CreateInfo(propertyInfo, attributes);
                    properties.Add(parameterInfo);

                    if (parameterInfo is CommandInfo commandInfo)
                    {
                        commandInfos.Add(commandInfo);
                        if (IsHelpCommand(propertyInfo))
                        {
                            HelpCommand = commandInfo;
                        }
                        if (commandInfo.IsDefault)
                        {
                            if (DefaultCommand != null)
                            {
                                throw new InvalidOperationException("Default command was defined twice.");
                            }

                            DefaultCommand = commandInfo;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void Initialize()
        {
            commandInfos = new List <CommandInfo>();
            properties   = new List <ParameterInfo>();

            foreach (var propertyInfo in ArgumentType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var attributes = (CommandLineAttribute[])propertyInfo.GetCustomAttributes(typeof(CommandLineAttribute), true);
                if (attributes.Any())
                {
                    var parameterInfo = CreateInfo(propertyInfo, attributes);
                    properties.Add(parameterInfo);

                    var commandInfo = parameterInfo as CommandInfo;
                    if (commandInfo != null)
                    {
                        commandInfos.Add(commandInfo);
                        if (IsHelpCommand(propertyInfo))
                        {
                            HelpCommand = commandInfo;
                        }
                    }
                }
            }
        }