Skip to content

Commands

Kevin Le Jeune edited this page Sep 8, 2016 · 6 revisions

Commands represent a user intention.

A command is a class containing:

  • basic type parameters
  • parameter and context checks
  • an action to execute

Example:

    private class DummyCommand : ICommand<string>
    {
        public static string FirstErrorMessage => "The first parameter must not be empty";

        public string FirstParameter { get; set; }
        public int SecondParameter { get; set; }

        public bool CheckParameters(IParameterChecker _)
        {
            return _.Check(() => this.FirstParameter, p => !string.IsNullOrWhiteSpace(p), FirstErrorMessage)
                   && _.Check(() => this.SecondParameter, p => p >= 0, FirstErrorMessage);
        }

        public bool CheckContext(ITeclynContext context, ICommandContextChecker _)
        {
            return true;
        }

        public void Execute(ICommandExecutionContext context)
        {
            this.Result = this.FirstParameter + this.SecondParameter;
        }

        public string Result { get; private set; }
    }
Clone this wiki locally