-
Notifications
You must be signed in to change notification settings - Fork 0
Rule basics
From version 0.4.0, rules are used to extend the functionalities of the library. In this page you will learn:
- what is a rule
- the different type of rules you can create
- the difference between generic rules and specific ones
- a practical example
A rule is a feature that extends the functionalities of the library. It is based on the attributes and types given to the arguments. If you don't know the concept of argument used by the library, see what is an argument and how to define it
Each argument is described in a class, ParameterDescriptor, that contains all information regarding the argument. These information are taken from the attributes and the type of the property
It is possible to decide if a rule should be executed or not, but it is not possible to define the order of execution, so it is strongly suggested that there aren't dependencies between rules in order to avoid unexpected behaviours. Moreover, take in mind that the first rules evaluated are the rules defined into the library, and then the rules defined by the user. The user rules are evaluated only for the arguments that require a user rule.
If an argument has a type created by the user or contains an attribute defined in another library, InterAppConnector will automatically check and evaluate the rules contained in these user libraries
There are two categories of rules:
- Argument definition rules
- Argument settings rules
Each category has two types of rules specializations:
- generic rules
- specialized rules
Argument definition rules are rules that are executed when the argument is created and defined. For this reason, they are the first rules evaluated by the library. For each of the argument created, the library creates a ParameterDescriptor object, that contains the informations about the argument (name, aliases, type, ...)
In order to define a rule that works at argument setting level, you have to create or use a class that implements the following interafces:
- For specific rules you have to implement the
IArgumentDefinitionRule<ArgumentType>interface - For generic rules you have to implement the
IArgumentDefinitionRuleinterface
For more information regarding argument definition rules, see the argument definitions rules page
Argument setting rules are evaluated after the argument definition ones. At this point, it is known also the value inserted by the user.
This is the right place for validators and all rules where the value inserted by the user is necessary to take decisions
In order to define a rule that works at argument setting level, you have to create or use a class that implements the following interafces:
- For specific rules you have to implement the
IArgumentSettingRule<ArgumentType>interface - For generic rules you have to implement the
IArgumentSettingRuleinterface
For more information regarding argument setting rules, see the argument setting rules page
Both levels described above supports two types of rules:
- generic rules
- specific rules.
Specific rules are associated to one attribute, while generic rules are not associated to anything. They are always evaluated and executed if enabled, and the algorithm used to execute the ruke is described below:
- if a rule is generic, the code inside
DefineArgumentIfTypeDoesNotExistorSetArgumentValueIfTypeDoesNotExistis executed - if a rule is specific to an attribute, the code inside
DefineArgumentIfTypeDoesNotExistis executed when the attribute does not exists, otherwise it is executed the code insideDefineArgumentIfTypeExists
This page is a simple explanation page. In order to understand better the concept of rules and how to use the diffferent rule types available in the library, it is suggested to follow these links:
- For examples regarding argument definition rules, see the argument definition rules page
- For examples regarding argument setting rules, see the argument setting rules page
- Getting started
- Create Commands
- Manage arguments
- Argument basics
- Shared arguments between different commands
- Argument aliases
- Argument description
- Exclude an argument from argument list
- Use enumerations as argument
- Use objects and structs as argument type
- Validate argument value before command execution
- Customize the command example in command help
- Define rules