TypeRegistry

Maps stable Guid identifiers (declared via TypeIdAttribute) to runtime Type instances and vice versa. Used by the polymorphic JSON serializers so that serialized data survives renames, namespace changes and assembly moves of the annotated classes.

Properties

Count

(int): Returns the count of currently registered types. Mainly useful for diagnostics and tests.

Public Methods

ScanLoadedAssemblies

public static void ScanLoadedAssemblies()

Scans every assembly currently loaded in the AppDomain for classes annotated with TypeIdAttribute and registers them. Already-scanned assemblies are skipped, but registrations are overwritten with the most recently scanned type so hot-reloaded user code wins over stale assemblies kept alive by lingering instances.

ScanAssembly

public static void ScanAssembly(Assembly assembly)

Scans a specific assembly for TypeIdAttribute-annotated classes and registers them.

Parameters:

  • assembly (Assembly)

Register

public static void Register(Guid id, Type type)

Registers a Type with its stable id. Subsequent registrations for the same id overwrite previous entries (this matters for hot-reload of user code, where a recompiled assembly produces a new Type instance for the same id).

Parameters:

  • id (Guid)
  • type (Type)

TryGetType

public static bool TryGetType(Guid id, Type? type)

Tries to look up a registered Type by its stable id.

Parameters:

  • id (Guid)
  • type (Type?)

Returns: bool

TryGetType

public static bool TryGetType(string fullName, Type? type)

Tries to look up a registered Type by its full name, the form asset catalogs record. Only current registrations are searched, so hot-reloaded user code wins.

Parameters:

  • fullName (string)
  • type (Type?)

Returns: bool

TryGetId

public static bool TryGetId(Type type, Guid id)

Tries to look up the stable id assigned to a Type.

Parameters:

  • type (Type)
  • id (Guid)

Returns: bool

GetTypeOrThrow

public static Type GetTypeOrThrow(Guid id)

Resolves a registered Type by id, or throws if no type is registered for the given id.

Parameters:

  • id (Guid)

Returns: Type

GetIdOrThrow

public static Guid GetIdOrThrow(Type type)

Returns the stable id assigned to a Type, or throws if the type is not annotated with TypeIdAttribute.

Parameters:

  • type (Type)

Returns: Guid

Reset

public static void Reset()

Clears all registrations and re-scans currently loaded assemblies. Intended to be called after user code is recompiled and reloaded.

RegisterFromManifest

public static void RegisterFromManifest(string manifestPath, ILogger logger)

Loads a usercode.typeids.json manifest from manifestPath and registers every entry into TypeRegistry by searching all currently loaded assemblies. Intended for use in play/export runtimes where user code is compiled as a static project reference (so no [TypeId] attributes exist on user types).

Parameters:

  • manifestPath (string)
  • logger (ILogger)