Table of Contents

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

world World

The 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

provider ComponentValidationManager.TryGetConstraintsDelegate

The 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 provider is 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

validator ComponentValidator<T>

The validation delegate.

Type Parameters

T

The component type to validate.

Exceptions

ArgumentNullException

Thrown when validator is null.

UnregisterValidator<T>()

Removes the custom validator for a component type.

public bool UnregisterValidator<T>() where T : struct, IComponent

Returns

bool

true if a validator was removed; false if no validator was registered.

Type Parameters

T

The 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

entity Entity

The entity receiving the component.

component T

The component data.

Type Parameters

T

The 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

components IReadOnlyList<(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

entity Entity

The newly created entity.

components IReadOnlyList<(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.