Skip to content

Applying custom rules when executing commands

JF Blouin edited this page Apr 12, 2019 · 3 revisions

You may include custom rules / logic when executing commands. For instance, you may have a parameter only required in case another has a specific value. For this, you need to write the rule in code.


The ParameterRule attribute

Derive a class from ParameterRuleAttribute, located in the CommandLineEngine.Attributes namespace, in order to create a rule in your language of choice. Then decorate the method parameter you wish to apply the rule. The rule will be evaluated when your command is executed.


Example:

public sealed class ParameterRuleTest : CommandLineEngine.Attributes.ParameterRuleAttribute
{
    public override bool Evaluate(InputArguments inputArguments, OperationResult operationResult)
    {
        return true;
    }
}

[CommandLineEngine.Attributes.Command()]
static int SingleCommand([ParameterRuleTest] string parameter) 
{

}
``

Clone this wiki locally