ComplexValueBuilder
Definition
Namespace: Corvus.Text.Json.Internal
Assembly: Corvus.Text.Json.dll
Source: ComplexValueBuilder.cs
Provides a high-performance, low-allocation builder for constructing complex JSON values (objects and arrays) within an IMutableJsonDocument.
public readonly struct ComplexValueBuilder
Remarks
ComplexValueBuilder is a ref struct designed for use in stack-based scenarios, enabling efficient construction of JSON objects and arrays by directly manipulating the underlying metadata database. This builder supports adding properties and items of various types, including primitives, strings, numbers, booleans, nulls, and complex/nested values. It also provides methods for starting and ending JSON objects and arrays, as well as for integrating with IMutableJsonDocument for document mutation. Typical usage involves creating a builder via Create, using AddProperty and AddItem methods to populate the structure, and then finalizing with EndObject or EndArray. This type is not thread-safe and must not be stored on the heap.
Properties
| Property | Type | Description |
|---|---|---|
| MemberCount | int |
Gets the number of members (properties or items) added to the current object or array. |
Methods
| Method | Description |
|---|---|
| AddItem | Adds an item to the current array as a UTF-8 string. |
| AddItemArrayValue | Adds an array of Int64 values as an item to the current array. |
| AddItemFormattedNumber(ReadOnlySpan<byte>) | Adds a formatted number item to the current array. |
| AddItemNull() | Adds a null item to the current array. |
| AddItemRawString(ReadOnlySpan<byte>, bool) | Adds an item to the current array as a raw string. |
| AddPrebakedProperty | |
| AddPrebakedPropertyFormattedNumber(ReadOnlySpan<byte>, ReadOnlySpan<byte>) | Adds a property with a formatted number value using a pre-baked property name blob. |
| AddPrebakedPropertyNullValue(ReadOnlySpan<byte>) | Adds a null property using a pre-baked property name blob. |
| AddProperty | |
| AddPropertyArrayValue | Adds a property with an array of Int64 values to the current object. |
| AddPropertyFormattedNumber | Adds a property with a formatted number value to the current object. |
| AddPropertyNull | Adds a property with a null value to the current object. |
| AddPropertyRawString | Adds a property with a raw string value to the current object, with control over escaping and unescaping. |
| Apply(ref T) | Apply an object instance value to the document. |
Create(IMutableJsonDocument, int) static |
Creates a new ComplexValueBuilder for the specified parent document, pre-allocating space for the given number of elements. |
| EndArray() | Ends the current JSON array, finalizing its structure in the builder. |
| EndItem(ref ComplexValueBuilder.ComplexValueHandle) | |
| EndObject() | Ends the current JSON object, finalizing its structure in the builder. |
| EndProperty(ref ComplexValueBuilder.ComplexValueHandle) | |
| InsertAndDispose(int, int, ref MetadataDb) | Inserts the built data into the specified MetadataDb at the given index and disposes this builder. |
| OverwriteAndDispose(int, int, int, int, ref MetadataDb) | Overwrites a range of data in the specified MetadataDb with the built data and disposes this builder. |
| RemoveProperty | Removes a property from the current object. |
| SetAndDispose(ref MetadataDb) | Transfers the built data to the specified MetadataDb and disposes this builder. |
| StartArray() | Starts a new JSON array in the builder. |
| StartItem() | Start an array item. |
| StartObject() | Starts a new JSON object in the builder. |
| StartPrebakedProperty(ReadOnlySpan<byte>) | Stores a pre-baked property name and returns a handle for complex value building. Use with EndProperty to complete the pr... |
| StartProperty | Add a property name to the current object. |
| TryApply(ref T) | Tries to apply an object instance value to the document. |
Applies To
| Product | Versions |
|---|---|
| .NET | 9, 10 |
| .NET Standard | 2.0, 2.1 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests.
Open an issue