Skip to content

API Host TypedDocumentOptions

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

TypedDocumentOptions

TDoc serialization options

Namespace: AuroraScript.Runtime.Serialization. Kind: sealed record. Applies to 4.0.0.

Back to .NET Host API Reference

Overview

TypedDocumentOptions controls TDoc formatting, type-name emission, and maximum nesting depth. It is an immutable record; create it with an object initializer or derive it from existing options using with.

Quick Reference

// Given a configured AuroraEngine named engine:
var value = ScriptDatum.FromString("Aurora");
var options = new TypedDocumentOptions
{
    Indented = false,
    EmitTypeNames = true,
    MaxDepth = 64,
};

var text = TypedDocumentSerializer.Serialize(engine, value, options);

Properties

Default

static readonly TypedDocumentOptions Default

Default options. Its Indented is true, EmitTypeNames is false, and MaxDepth is 128.

Parameters

None.

Returns

Default TypedDocumentOptions instance.

Simple Example

// Given a configured AuroraEngine named engine:
// Given a ScriptDatum named value:
var text = TypedDocumentSerializer.Serialize(engine, value, TypedDocumentOptions.Default);

Indented

bool Indented

Controls output formatting. It defaults to true, using four-space indentation, newlines, and trailing commas; false produces compact text without formatting whitespace.

This option does not alter string values. Carriage return, line feed, and form-feed characters originally inside a string are always written as \r, \n, and \f escapes so reading restores the exact value; they are not physical line breaks introduced by compact formatting.

Parameters

None.

Returns

Whether indented text is emitted.

Simple Example

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

EmitTypeNames

bool EmitTypeNames

Controls whether a type name is written before each typed value. It defaults to false, emitting only type names that cannot be uniquely inferred from raw literals.

When set to true, it forces every available type name. Regardless of this value, StringBuffer, Date, Regex, Path, HashMap, every packed array, and registered CLR/CIL type must emit a type name because their raw shapes do not uniquely determine the type.

Parameters

None.

Returns

Whether all available type names are emitted.

Simple Example

// Given a configured AuroraEngine named engine:
var options = new TypedDocumentOptions
{
    Indented = false,
    EmitTypeNames = true,
};

var text = TypedDocumentSerializer.Serialize(engine, ScriptDatum.FromString("Aurora"), options);
// String "Aurora"

MaxDepth

int MaxDepth

Limits nested value depth for both reading and writing. It defaults to 128 and must be greater than zero; zero or a negative value throws ArgumentOutOfRangeException before the operation begins.

Parameters

None.

Returns

Maximum permitted nested-value depth.

Simple Example

// Given a configured AuroraEngine named engine:
var options = new TypedDocumentOptions { MaxDepth = 32 };
var value = TypedDocumentSerializer.Deserialize(engine, "Array [1, 2]", options);

Selection Guidance

Use defaults for human-maintained configuration, Indented = false for compact cache or wire text, EmitTypeNames = true for review, diffs, or explicit data contracts, and set a business-appropriate smaller MaxDepth for untrusted or deeply nested input.

Related APIs

Clone this wiki locally