Table of Contents

Interface IComponentSerializer

Namespace
KeenEyes.Serialization
Assembly
KeenEyes.Core.dll

Interface for AOT-compatible component serialization.

public interface IComponentSerializer

Examples

// Use generated serializer for AOT compatibility
var serializer = new ComponentSerializationRegistry();
SnapshotManager.RestoreSnapshot(world, snapshot, serializer: serializer);

Remarks

This interface is implemented by generated code when components are marked with [Component(Serializable = true)]. The source generator creates a strongly-typed implementation that avoids runtime reflection.

For applications requiring AOT compatibility, pass the generated serializer to RestoreSnapshot(World, WorldSnapshot, IComponentSerializer) instead of relying on reflection.

Methods

CreateDefault(string)

Creates a default instance of a component type.

object? CreateDefault(string typeName)

Parameters

typeName string

The fully-qualified type name of the component.

Returns

object

A default instance of the component, or null if the type is not registered.

Remarks

This method enables AOT-compatible default value creation without reflection. The implementation should return default(T) for the appropriate type. This is primarily used for tag components during delta restoration.

Deserialize(string, JsonElement)

Deserializes a component from JSON.

object? Deserialize(string typeName, JsonElement json)

Parameters

typeName string

The fully-qualified type name of the component.

json JsonElement

The JSON element containing the component data.

Returns

object

The deserialized component, or null if the type is not registered.

GetType(string)

Gets the CLR type for a type name.

Type? GetType(string typeName)

Parameters

typeName string

The fully-qualified type name.

Returns

Type

The CLR type, or null if not registered.

IsSerializable(string)

Checks if a component type name is registered for serialization.

bool IsSerializable(string typeName)

Parameters

typeName string

The fully-qualified type name to check.

Returns

bool

True if the type can be serialized; false otherwise.

IsSerializable(Type)

Checks if a component type is registered for serialization.

bool IsSerializable(Type type)

Parameters

type Type

The component type to check.

Returns

bool

True if the type can be serialized; false otherwise.

RegisterComponent(ISerializationCapability, string, bool)

Registers a component type in the world's component registry.

ComponentInfo? RegisterComponent(ISerializationCapability serialization, string typeName, bool isTag)

Parameters

serialization ISerializationCapability

The serialization capability providing component registry access.

typeName string

The fully-qualified type name of the component.

isTag bool

Whether the component is a tag component.

Returns

ComponentInfo

The component info, or null if the type is not registered in this serializer.

Remarks

This method enables AOT-compatible component registration without reflection. The implementation should call serialization.Components.Register<T>(isTag) for the appropriate type.

Serialize(Type, object)

Serializes a component to JSON.

JsonElement? Serialize(Type type, object value)

Parameters

type Type

The type of the component.

value object

The component value to serialize.

Returns

JsonElement?

The serialized JSON element, or null if the type is not registered.

SetSingleton(ISerializationCapability, string, object)

Sets a singleton value in the world.

bool SetSingleton(ISerializationCapability serialization, string typeName, object value)

Parameters

serialization ISerializationCapability

The serialization capability providing singleton access.

typeName string

The fully-qualified type name of the singleton.

value object

The singleton value.

Returns

bool

True if the singleton was set; false if the type is not registered.

Remarks

This method enables AOT-compatible singleton setting without reflection. The implementation should call serialization.SetSingleton<T>((T)value) for the appropriate type.