Exemplo n.º 1
0
    public void AddBranch <TSettings>(string name, Action <IConfigurator <TSettings> > action)
        where TSettings : CommandSettings
    {
        var command = ConfiguredCommand.FromBranch <TSettings>(name);

        action(new Configurator <TSettings>(command, _registrar));
        Commands.Add(command);
    }
Exemplo n.º 2
0
    public void AddBranch <TDerivedSettings>(string name, Action <IConfigurator <TDerivedSettings> > action)
        where TDerivedSettings : TSettings
    {
        var command = ConfiguredCommand.FromBranch <TDerivedSettings>(name);

        action(new Configurator <TDerivedSettings>(command, _registrar));
        _command.Children.Add(command);
    }
Exemplo n.º 3
0
    void IUnsafeConfigurator.AddBranch(string name, Type settings, Action <IUnsafeBranchConfigurator> action)
    {
        var command = ConfiguredCommand.FromBranch(settings, name);

        // Create the configurator.
        var configuratorType = typeof(Configurator <>).MakeGenericType(settings);

        if (!(Activator.CreateInstance(configuratorType, new object?[] { command, _registrar }) is IUnsafeBranchConfigurator configurator))
        {
            throw new CommandConfigurationException("Could not create configurator by reflection.");
        }

        action(configurator);
        Commands.Add(command);
    }