ComponentTypeRegistry Class
Definition
Namespace: Brine2D.ECS.Serialization
Registry that maps component types to their serialization delegates for use with AotEntitySerializer. Register each component type once at startup; AotEntitySerializer will use the registered delegates for every serialize/deserialize/attach operation.
Inheritance System.Object → ComponentTypeRegistry
Remarks
Three registration tiers, in order of AOT-safety:
1. Fully AOT-safe:Register<T>\(JsonTypeInfo<T>\).
Supply a source-generated System.Text.Json.Serialization.Metadata.JsonTypeInfo<> from your own
[JsonSerializable]-annotated JsonSerializerContext.
Zero runtime reflection; compatible with NativeAOT and IL trimming.
Best when you publish with <PublishTrimmed>true</PublishTrimmed>
and only need to cover a handful of custom component types.
2. Reflection, explicit:Register<T>().
No [JsonSerializable] needed; the registry derives JSON metadata at
runtime. Annotated with [RequiresDynamicCode] and
[RequiresUnreferencedCode] so the trimmer surfaces any trimmed-publish
usages during analysis. Suitable for non-trimmed publishing.
3. Reflection, automatic:RegisterAllComponents\(Assembly\[\]\) and
RegisterBrineComponents().
Scans one or more System.Reflection.Assembly instances and registers every
concrete (non-abstract, non-generic) Component subclass it finds.
One call covers all components in the assembly with zero per-type boilerplate.
Same AOT restrictions as tier 2; not suitable for trimmed publishing.
Typical setup (non-trimmed):
var registry = new ComponentTypeRegistry();
registry.RegisterBrineComponents(); // all built-in engine components
registry.RegisterAllComponents(GetType().Assembly); // all your game's components
var serializer = new AotEntitySerializer(registry);
| Properties | |
|---|---|
| Count | The number of component types currently registered. |
| Methods | |
|---|---|
| IsRegistered\(string\) | Returns whether the given type name has a registration. |
| IsRegistered<T>() | Returns whether a component type has been registered under its full type name. |
| Register<T>() | Registers a single component type using the default System.Text.Json.JsonSerializerOptions \(camelCase, enums as strings, [System\.Numerics\.Vector2](https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector2 'System\.Numerics\.Vector2') converter\). |
| Register<T>\(JsonTypeInfo<T>\) | Registers a component type using a source-generated System.Text.Json.Serialization.Metadata.JsonTypeInfo<>. This is the fully AOT-safe registration path. |
| RegisterAllComponents\(Assembly\[\]\) | Scans the provided assemblies and automatically registers every concrete \(non\-abstract, non\-generic, publicly constructible\) Component subclass found. Abstract base classes and open generic types are skipped. |
| RegisterBrineComponents() | Registers all concrete Component subclasses built into the Brine2D engine. Equivalent to RegisterAllComponents(typeof(Component).Assembly). |