Class ComponentValidationManager
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Manages component validation constraints including dependencies, conflicts, and custom validators.
public sealed class ComponentValidationManager
- Inheritance
-
ComponentValidationManager
- Inherited Members
Remarks
The validation manager reads KeenEyes.RequiresComponentAttribute and KeenEyes.ConflictsWithAttribute from component types and caches the results for efficient runtime validation.
Validation can be controlled using KeenEyes.ValidationMode:
- KeenEyes.ValidationMode.Enabled - Always validate (default)
- KeenEyes.ValidationMode.Disabled - Skip all validation
- KeenEyes.ValidationMode.DebugOnly - Only validate when DEBUG is defined
This class is thread-safe: validation and registration operations can be called concurrently from multiple threads.
Constructors
ComponentValidationManager(World)
Manages component validation constraints including dependencies, conflicts, and custom validators.
public ComponentValidationManager(World world)
Parameters
worldWorldThe world this manager belongs to.
Remarks
The validation manager reads KeenEyes.RequiresComponentAttribute and KeenEyes.ConflictsWithAttribute from component types and caches the results for efficient runtime validation.
Validation can be controlled using KeenEyes.ValidationMode:
- KeenEyes.ValidationMode.Enabled - Always validate (default)
- KeenEyes.ValidationMode.Disabled - Skip all validation
- KeenEyes.ValidationMode.DebugOnly - Only validate when DEBUG is defined
This class is thread-safe: validation and registration operations can be called concurrently from multiple threads.
Properties
Mode
Gets or sets the validation mode for this manager.
public ValidationMode Mode { get; set; }
Property Value
- ValidationMode
Methods
RegisterConstraintProvider(TryGetConstraintsDelegate)
Registers a constraint provider for AOT-compatible validation metadata lookup.
public void RegisterConstraintProvider(ComponentValidationManager.TryGetConstraintsDelegate provider)
Parameters
providerComponentValidationManager.TryGetConstraintsDelegateThe delegate that provides validation constraints for component types.
Remarks
This method enables AOT-compatible constraint lookup without assembly scanning or reflection.
The source generator creates a ComponentValidationMetadata class with a static
TryGetConstraints method that should be registered here.
Register the constraint provider when creating the world:
var world = new World();
world.ValidationManager.RegisterConstraintProvider(ComponentValidationMetadata.TryGetConstraints);
Each world has its own constraint provider, following the per-world isolation principle.
Exceptions
- ArgumentNullException
Thrown when
provideris null.
RegisterValidator<T>(ComponentValidator<T>)
Registers a custom validator for a component type.
public void RegisterValidator<T>(ComponentValidator<T> validator) where T : struct, IComponent
Parameters
validatorComponentValidator<T>The validation delegate.
Type Parameters
TThe component type to validate.
Exceptions
- ArgumentNullException
Thrown when
validatoris null.
UnregisterValidator<T>()
Removes the custom validator for a component type.
public bool UnregisterValidator<T>() where T : struct, IComponent
Returns
- bool
trueif a validator was removed;falseif no validator was registered.
Type Parameters
TThe component type.
ValidateAdd<T>(Entity, in T)
Validates a component being added to an existing entity.
public void ValidateAdd<T>(Entity entity, in T component) where T : struct, IComponent
Parameters
entityEntityThe entity receiving the component.
componentTThe component data.
Type Parameters
TThe component type.
Exceptions
- ComponentValidationException
Thrown when validation fails.
ValidateBuild(IReadOnlyList<(ComponentInfo Info, object Data)>)
Validates a set of components being added during entity creation.
public void ValidateBuild(IReadOnlyList<(ComponentInfo Info, object Data)> components)
Parameters
componentsIReadOnlyList<(ComponentInfo Info, object Data)>The components being added.
Exceptions
- ComponentValidationException
Thrown when validation fails.
ValidateBuildCustom(Entity, IReadOnlyList<(ComponentInfo Info, object Data)>)
Validates a set of components being added during entity creation, including custom validators.
public void ValidateBuildCustom(Entity entity, IReadOnlyList<(ComponentInfo Info, object Data)> components)
Parameters
entityEntityThe newly created entity.
componentsIReadOnlyList<(ComponentInfo Info, object Data)>The components that were added.
Remarks
Uses KeenEyes.ComponentInfo.InvokeValidator delegate for AOT-compatible validation without reflection.
Exceptions
- ComponentValidationException
Thrown when custom validation fails.