コード例 #1
0
        protected internal override void Attach(RootCommandBase rootCommand, List <Tuple <Type, Type> > subCommandTypes)
        {
            base.Attach(rootCommand, null);

            subCommandTypes = SubCommandTypes.Union(subCommandTypes ?? new List <Tuple <Type, Type> >()).ToList();
            var subCommandsToPassOn = new List <Tuple <Type, Type> >();

            if (subCommandTypes.Any())
            {
                if (RootCommand.CommandResolver == null)
                {
                    throw new InvalidOperationException("No CommandResolver has been defined in the root command.");
                }

                foreach (var subCommandType in subCommandTypes)
                {
                    if (subCommandType.Item2 == null || subCommandType.Item2 == this.GetType())
                    {
                        var command = RootCommand.CommandResolver.Resolve(subCommandType.Item1);
                        RegisterCommand(command);
                    }
                    else if (subCommandType.Item2 != null)
                    {
                        subCommandsToPassOn.Add(subCommandType);
                    }
                }
            }

            foreach (var cmd in SubCommands)
            {
                var c = cmd as CommandBase;
                c?.Attach(rootCommand, subCommandsToPassOn);
            }
        }
コード例 #2
0
        protected internal virtual void Attach(RootCommandBase rootCommand, List <Tuple <Type, Type> > subCommandTypes)
        {
            if (rootCommand == null)
            {
                throw new ArgumentNullException(nameof(rootCommand), "No rootCommand provided");
            }
            if (RootCommand != null)
            {
                throw new InvalidOperationException("The command is already attached.");
            }

            RootCommand = rootCommand;
        }
コード例 #3
0
        protected internal override void Attach(RootCommandBase rootCommand)
        {
            base.Attach(rootCommand);

            if (SubCommandTypes.Any())
            {
                if (RootCommand.CommandResolver == null)
                {
                    throw new InvalidOperationException("No CommandResolver has been defined.");
                }

                foreach (var subCommandType in SubCommandTypes)
                {
                    var command = RootCommand.CommandResolver.Resolve(subCommandType);
                    RegisterCommand(command);
                }
            }

            foreach (var cmd in SubCommands)
            {
                var c = cmd as CommandBase;
                c?.Attach(rootCommand);
            }
        }