Tutorial (sprint2)

This tutorial explains how to use the Validation Engine of QInjection (version "Sprint 2 - Arechi").
I'll illustrate how to set up it for different kind of lambda expressions.

Understanding the Support and As methods

Internally the validation engine builds the AST (Abstract Syntax Tree) of the lambda expression and it walks throught it by validating each branch.
An AST is composed by Node and Branches. So declaring the syntax of a lambda expression means to define the "composition" of the Tree in term of Nodes, Branches and Links between them. This is made using two mains methods of the QInjector class:

Support(Node): this method sets the Node on which the declarations are applied on.

As(Branch): this method adds the Node as valid element on a specific branch.

If you apply a restriction on a node than only "lamda expression" that conforms to the rule will be accepted.
Let me to clarify: for a Node BinaryExpression withouth restriction than any operator will accepted, but if you add restrictions on operators Plus (+) and Equals (==) then only lambda expression containing {+} and == inside binary expression will be accepted.

Syntax of a Validation Rule

A validation rule starts with the method Support(...) and can contains many As(...) and With*(...) methods invocation.

The first "branch" evaluated is the "input branch" and it has to be a Node.SimpleLambdaExpression.
The "Support(...).As(...)" on the node Node.Parameter is used for parsing the Parameter branch of the Lambda Expression.