Skip to content

API Host ClrTypeRegistry

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

ClrTypeRegistry

Host-side registry mapping script-visible aliases to CLR types.

Namespace: AuroraScript.Runtime.Interop. Kind: class.

Back to .NET Host API Reference

Overview

ClrTypeRegistry maps script aliases to CLR types. Registration grants capability to scripts, so register reviewed types only and expose the smallest suitable TypeAccess.

An engine owns one registry, reachable as AuroraEngine.ClrRegistry. AuroraEngine.RegisterType is a shortcut over the same registry.

Warning

A registered alias is a capability handed to every script the engine runs. Prefer TypeAccess.Constructor or TypeAccess.Static over TypeAccess.All when the script only needs one of them.

Quick Reference

A minimal use of ClrTypeRegistry.

engine.ClrRegistry.RegisterType(typeof(HostCalculator), "Calculator", TypeAccess.All);

Methods

RegisterType

void RegisterType(Type type, string alias, TypeAccess access)

Registers a CLR type under a script-visible alias.

Parameters

Name Type Required Description
type Type Yes CLR type to expose.
alias string Yes Script-visible alias.
access TypeAccess Yes Allowed constructor and static-member access.

Returns

None.

engine.ClrRegistry.RegisterType(typeof(HostCalculator), "Calculator", TypeAccess.All);

UnregisterType

bool UnregisterType(string alias)

Removes a registration by alias.

Parameters

Name Type Required Description
alias string Yes Script alias to remove.

Returns

true when a registration was removed; otherwise false.

var removed = engine.ClrRegistry.UnregisterType("Calculator");

TryGetClrType

bool TryGetClrType(string alias, out ClrType descriptor)

Looks up the descriptor registered for an alias.

Parameters

Name Type Required Description
alias string Yes Script alias to look up.
descriptor out ClrType Yes Receives the ClrType descriptor.

Returns

true when a registration exists; otherwise false.

if (engine.ClrRegistry.TryGetClrType("Calculator", out var descriptor))
{
    Console.WriteLine(descriptor);
}

Dispose

void Dispose()

Releases registry-lifetime resources.

Parameters

None.

Returns

None.

Behavior

The registry is normally managed with the owning engine's lifetime; dispose it explicitly only when the host owns the registry directly.

engine.ClrRegistry.Dispose();

Access Levels

TypeAccess selects which members an alias exposes. Instance members are available only from successfully constructed or host-injected instances.

Value Exposes
Constructor Constructors only.
Static Static members only.
All Constructors and static members.
engine.RegisterType<HostCalculator>("Calculator", TypeAccess.Constructor);
engine.RegisterType<HostMath>("HostMath", TypeAccess.Static);
engine.RegisterType<HostCalculator>("Calculator", TypeAccess.All);

Clone this wiki locally