Templates are used to facilitate reuse. nspectre uses the Ader Templating Engine. Full documentation and sourcecode can be found here.
A template in nspectre is the template of a specification. At runtime nspectre generates the appropriate code to create the specification(s) based on the template. Note that by holding a reference to an IValidatorFactory, the code is only generated once.
A template can be a string, a file or an embedded resource. The format of the name of an embedded resource is namespace.resourcename.extension, assemblyname.
For example, assume that there is a User class with a property called EmailAddress. We want to create a specification that checks that this property is not null. Before we can write the specification, we need to write the template. This is the template we need to write:
return (target.#property# != null);
In the specification we will bind EmailAddress to property. We can use the same template to check that a different property on the same class is not null or, indeed, any property on any class.
When writing templates note that target is used to refer to the object being validated and that there should be a return statement. True or false (indicating whether or not the specification is satisifed) should be returned.