c#public LaunchOptions {}public LaunchCommand : Command<LaunchOptions> {}List<Command<object>> commands = new List<Command<object>>();commands.Add(new LaunchCommand());
C#public abstract class Command<TOptions, TResponse> : ICommand<TOptions, TResponse>{ public abstract IResult<TResponse?> Execute(TOptions options); public IResult<TResponse?> Execute(object options) { return Execute((TOptions)options); }}public abstract class Command<TOptions> : ICommand<TOptions>{ public abstract IResult<object?> Execute(TOptions options); public IResult<object?> Execute(object options) { return Execute((TOptions)options); }}public abstract class Command : ICommand{ public abstract IResult<object?> Execute(object options);}
c#private static IResult<object?> ExecuteCommand(string name, string[] args) { switch(name) { case "Deploy": return (new DeployCommand()) .Execute(CreateOptions<DeployOptions>(args)); case "Launch": return (new LaunchCommand()) .Execute(CreateOptions<LaunchOptions>(args)); default: throw new ArgumentException(); } }}
c#class MyCommand : Command<CommandOptions>{ ...}ICommand<object> command = (Command<object>)new MyCommand();
public abstract class Command<TOptions, TResponse> : ICommand<TOptions, TResponse>{ public abstract IResult<TResponse?> Execute(TOptions options); public IResult<TResponse?> Execute(object options) { return Execute((TOptions)options); }}public abstract class Command<TOptions> : ICommand<TOptions>{ public abstract IResult<object?> Execute(TOptions options); public IResult<object?> Execute(object options) { return Execute((TOptions)options); }}public abstract class Command : ICommand{ public abstract IResult<object?> Execute(object options);}
1. Program.exe MyCommandName2. MyCommandName - Goes into -> FactoryMethod(MyCommandName)3. FactoryMethod(MyCommandName) - Returns -> Command, Options