Skip to content

API Host TypedDocumentSerializer

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

TypedDocumentSerializer

Static TDoc text serializer

Namespace: AuroraScript.Runtime.Serialization. Kind: static class. Applies to 4.0.0.

Back to .NET Host API Reference

Overview

TypedDocumentSerializer is the minimal host text API: given an AuroraEngine, a ScriptDatum, or text, it directly serializes or deserializes TDoc.

It suits one-off text conversion. Use AuroraTypedDocument when reusing an engine or reading and writing files or streams.

Quick Reference

using AuroraScript;
using AuroraScript.Runtime;
using AuroraScript.Runtime.Serialization;
using System;

var engine = new AuroraEngine(EngineOptions.Default);
var text = TypedDocumentSerializer.Serialize(engine, ScriptDatum.FromString("Aurora"));
var value = TypedDocumentSerializer.Deserialize(engine, text);

Console.WriteLine(value); // Aurora

Methods

Serialize

static string Serialize(AuroraEngine engine, ScriptDatum value, TypedDocumentOptions options = null)

Writes one AuroraScript value as standalone TDoc text.

Parameters

Name Type Required Description
engine AuroraEngine Yes AuroraScript engine used for date formatting and the CLR/CIL type registry. Cannot be null.
value ScriptDatum Yes AuroraScript value to serialize.
options TypedDocumentOptions No Optional text options; TypedDocumentOptions.Default is used when null.

Returns

TDoc text.

Behavior and exceptions

Text contains no script tdoc marker; the default uses four-space indentation, trailing commas, and only type names that cannot be inferred from literals. Writing an unrepresentable runtime value does not fail because of that value: object properties are omitted; array elements and unrepresentable keys or values in a HashMap entry become null; and a root value becomes null. This includes functions, proxies, accessor properties, unregistered CLR/CIL objects, non-finite Numbers, and previously seen circular/shared references. Enumerable prototype properties of a ScriptObject are written as flat visible members; reading does not restore the prototype chain.

Simple Example

// Given a configured AuroraEngine named engine:
var text = TypedDocumentSerializer.Serialize(
    engine,
    ScriptDatum.FromNumber(42.5),
    new TypedDocumentOptions { Indented = false });

Console.WriteLine(text); // 42.5

Deserialize

static ScriptDatum Deserialize(AuroraEngine engine, string text, TypedDocumentOptions options = null)

Reads standalone TDoc text as ScriptDatum. Root primitive values keep their original kind instead of always being wrapped as ScriptObject.

Parameters

Name Type Required Description
engine AuroraEngine Yes AuroraScript engine used for date formatting and the CLR/CIL type registry. Cannot be null.
text string Yes Complete TDoc text to read. Cannot be null.
options TypedDocumentOptions No Optional read and diagnostic options; TypedDocumentOptions.Default is used when null.

Returns

Parsed ScriptDatum.

Behavior and exceptions

Text may contain one root value only; unknown types, invalid type shapes, duplicate properties, or depth-limit violations throw TypedDocumentException. Date strings must match the engine Runtime.DateTimeFormat; CLR/CIL aliases must already be registered on the current engine.

Behavior

EmitTypeNames defaults to false. By default it omits Object, Array, String, Number, and Boolean when a raw literal uniquely infers them; packed arrays and CLR/CIL types always retain type names. Set it to true to force every available type name.

// Given a configured AuroraEngine named engine:
var compact = TypedDocumentSerializer.Serialize(
    engine,
    ScriptDatum.FromString("Aurora"),
    new TypedDocumentOptions { Indented = false, EmitTypeNames = true });

Console.WriteLine(compact); // String "Aurora"

Related APIs

Clone this wiki locally