ValidateMetadata<T> Class
Tests metadata for existence, typing, and supplied assertions.
Namespace
Statiq.Core
Interfaces
Base Types
graph BT Type-->Base0["Module"] click Base0 "/api/Statiq.Common/Module" Base0-->Base1["object"] Type-.->Interface0["IModule"] click Interface0 "/api/Statiq.Common/IModule" Type["ValidateMetadata<T>"] class Type type-node

Syntax

public class ValidateMetadata<T> : Module, IModule

Examples

This example will ensure "Title" exists. (It will also perform a type check, but since "object" matches anything, the type check will always succeed.)
ValidateMeta<object>("Title")
This example will ensure that if "Date" exists, it can convert to a valid DateTime.
ValidateMeta<DateTime>("Date")
   .IsOptional()
This example will ensure "Age" (1) exists, (2) can convert to an integer, (3) and is greater than 0 and less than 121. If it fails any assertion, the provided error message will be output. (In this case, those two assertions could be rolled into one, but then they would share an error message. Separate assertions allow more specific error messages.) Assertions will be checked in order. Any assertion can assume all previous assertions have passed. Error messages will be appended with the document Source and Id properties to assist in identifying invalid documents.
ValidateMeta<int>("Age")
   .WithAssertion(a => a > 0, "You have to be born.")
   .WithAssertion(a => a <= 120, "You are way, way too old.")

Remarks

This module performs tests on metadata. It can ensure metadata exists, that it can be converted to the correct type, and that is passes arbitrary tests (delegates) to ensure validity. Metadata can be specified as optional, in which case, typing and assertion testing will only be run if the metadata exists. If any check fails, this module throws an exception with a descriptive error message then halts further execution.

Type Parameters

Name Description
T The type of the metadata value to convert to for validation.

Constructors

Name Summary
ValidateMetadata(string) Performs validation checks on metadata.

Methods

Name Return Value Summary
AfterExecution(IExecutionContext, ExecutionOutputs) void
Called after each module execution.
Inherited from Module
AfterExecutionAsync(IExecutionContext, ExecutionOutputs) Task
Called after each module execution.
Inherited from Module
BeforeExecution(IExecutionContext) void
Called before each module execution.
Inherited from Module
BeforeExecutionAsync(IExecutionContext) Task
Called before each module execution.
Inherited from Module
ExecuteAsync(IExecutionContext) Task<IEnumerable<IDocument>>
This should not be called directly, instead call IExecutionContext.Execute() if you need to execute a module from within another module.
Inherited from Module
ExecuteContextAsync(IExecutionContext) Task<IEnumerable<IDocument>>
Executes the module once for all input documents.
ExecuteInputAsync(IDocument, IExecutionContext) Task<IEnumerable<IDocument>>
Executes the module.
Inherited from Module
Finally(IExecutionContext) void
Called after each module execution, even if an exception is thrown during execution.
Inherited from Module
FinallyAsync(IExecutionContext) Task
Called after each module execution, even if an exception is thrown during execution.
Inherited from Module
IsOptional() ValidateMetadata<T>
Declares the entire check as optional. Is this is set, and the meta key doesn't exist, no checks will be run.
WithAssertion(Func<T, bool>, string) ValidateMetadata<T>
Performs validation checks on metadata.

Extension Methods