Open sandboxFocus

Method Validate

Validate(dynamic?)

The template method that validates or normalizes the value of a field, property, indexer, or parameter.

Declaration
public override void Validate(dynamic? value)
Parameters
Type Name Description
dynamic value

The value to validate or normalize. This is a dynamic parameter to support any value type.

Overrides
Remarks

This is the primary template method that must be implemented in derived contract aspects. It is executed at the point in the data flow determined by GetDefinedDirection(IAspectBuilder), which can be input (precondition), output (postcondition), or both.

Within the template, use meta.Target.ContractDirection to determine whether you're validating input or output flow. Access the target through meta.Target.Expression (unified access to field, property, or parameter), or use meta.Target.FieldOrProperty / meta.Target.Parameter for specific access.

To reject invalid values, throw an appropriate exception (typically ArgumentException for parameters, or a custom validation exception). To normalize values, modify the value parameter using assignment (e.g., value = value.Trim()), which will update the value in the data flow.