<PackageReference Include="System.Text.Json" Version="10.0.0-preview.4.25258.110" />

JsonWriterOptions

public struct JsonWriterOptions
Allows the user to define custom behavior when writing JSON using the Utf8JsonWriter.
using System.Runtime.CompilerServices; using System.Text.Encodings.Web; namespace System.Text.Json { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public struct JsonWriterOptions { private static readonly string s_alternateNewLine = (Environment.NewLine.Length == 2) ? "\n" : "\r\n"; internal const int DefaultMaxDepth = 1000; private int _maxDepth; private int _optionsMask; private const int OptionsBitCount = 4; private const int IndentBit = 1; private const int SkipValidationBit = 2; private const int NewLineBit = 4; private const int IndentCharacterBit = 8; private const int IndentSizeMask = 2032; [System.Runtime.CompilerServices.Nullable(2)] public JavaScriptEncoder Encoder { [System.Runtime.CompilerServices.IsReadOnly] [System.Runtime.CompilerServices.NullableContext(2)] get; [System.Runtime.CompilerServices.NullableContext(2)] set; } public bool Indented { get { return (_optionsMask & 1) != 0; } set { if (value) _optionsMask |= 1; else _optionsMask &= -2; } } public char IndentCharacter { [System.Runtime.CompilerServices.IsReadOnly] get { if ((_optionsMask & 8) == 0) return ' '; return '\t'; } set { JsonWriterHelper.ValidateIndentCharacter(value); if (value != ' ') _optionsMask |= 8; else _optionsMask &= -9; } } public int IndentSize { [System.Runtime.CompilerServices.IsReadOnly] get { return EncodeIndentSize((_optionsMask & 2032) >> 4); } set { JsonWriterHelper.ValidateIndentSize(value); _optionsMask = ((_optionsMask & -2033) | (EncodeIndentSize(value) << 4)); } } public int MaxDepth { [System.Runtime.CompilerServices.IsReadOnly] get { return _maxDepth; } set { if (value < 0) ThrowHelper.ThrowArgumentOutOfRangeException_MaxDepthMustBePositive("value"); _maxDepth = value; } } public bool SkipValidation { get { return (_optionsMask & 2) != 0; } set { if (value) _optionsMask |= 2; else _optionsMask &= -3; } } public string NewLine { get { if ((_optionsMask & 4) == 0) return Environment.NewLine; return s_alternateNewLine; } set { JsonWriterHelper.ValidateNewLine(value); if (value != Environment.NewLine) _optionsMask |= 4; else _optionsMask &= -5; } } internal bool IndentedOrNotSkipValidation => (_optionsMask & 3) != 2; private static int EncodeIndentSize(int value) { switch (value) { case 0: return 2; case 2: return 0; default: return value; } } } }