JsonElement.ObjectBuilder
Definition
Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: JsonElement.ObjectBuilder.cs
public readonly struct JsonElement.ObjectBuilder
Constructors
| Constructor | Description |
|---|---|
| JsonElement.ObjectBuilder() |
Methods
| Method | Description |
|---|---|
| AddArrayValue | |
| AddFormattedNumber | |
| AddProperty | |
| AddPropertyNull | |
| AddRawString | |
BuildValue static |
|
| RemoveProperty | |
| TryApply(ref TApplicator) |
Examples
Use ObjectBuilder inside a Build() delegate to compose object values with named properties.
Person.PersonNameEntity name = Person.PersonNameEntity.Build(
(ref Person.PersonNameEntity.Builder b) => b.Create(
familyName: "Oldroyd"u8,
givenName: "Michael"u8));
The AddProperty method adds key-value pairs to the builder. It is used internally by the Create() method and is available for advanced scenarios where you need to build an object dynamically:
using var builder = workspace.BuildDocument<JsonElement.Mutable>(
initialCapacity: 10,
initialValueBufferSize: 256);
JsonElement.Mutable root = builder.RootElement;
root.SetProperty(
"name"u8,
JsonElement.Build(static (ref JsonElement.ObjectBuilder b) =>
{
b.AddProperty("familyName"u8, "Oldroyd"u8);
b.AddProperty("givenName"u8, "Michael"u8);
}));
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