Interface IValidationCapability
- Namespace
- KeenEyes.Capabilities
- Assembly
- KeenEyes.Abstractions.dll
Capability interface for component validation configuration.
public interface IValidationCapability
Examples
public void Install(IPluginContext context)
{
if (context.TryGetCapability<IValidationCapability>(out var validation))
{
// Disable validation for performance in production
validation.ValidationMode = ValidationMode.DebugOnly;
// Register a custom validator
validation.RegisterValidator<Health>((world, entity, health) =>
health.Current >= 0 && health.Current <= health.Max);
}
}
Remarks
This capability provides access to component validation settings and custom validator registration. Plugins that need to configure validation behavior or register custom validators should request this capability via GetCapability<T>().
Validation checks component constraints when components are added to entities, helping catch invalid component combinations at runtime.
Properties
ValidationMode
Gets or sets the validation mode for component constraints.
ValidationMode ValidationMode { get; set; }
Property Value
Remarks
Available modes:
Methods
RegisterValidator<T>(ComponentValidator<T>)
Registers a custom validator for a component type.
void RegisterValidator<T>(ComponentValidator<T> validator) where T : struct, IComponent
Parameters
validatorComponentValidator<T>A delegate that receives the world, entity, and component data, and returns true if validation passes.
Type Parameters
TThe component type to validate.
Exceptions
- ArgumentNullException
Thrown when validator is null.
UnregisterValidator<T>()
Removes a previously registered custom validator for a component type.
bool UnregisterValidator<T>() where T : struct, IComponent
Returns
- bool
True if a validator was removed; false if no validator was registered.
Type Parameters
TThe component type.