< Summary

Line coverage
4%
Covered lines: 11
Uncovered lines: 245
Coverable lines: 256
Total lines: 1115
Line coverage: 4.2%
Branch coverage
2%
Covered branches: 2
Total branches: 88
Branch coverage: 2.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: .cctor()100%110%
File 1: .ctor(...)100%11100%
File 1: AsArray()0%220%
File 1: AsObject()0%220%
File 1: AsValue()0%220%
File 1: GetPath()0%220%
File 1: GetValue()100%110%
File 1: GetItem(...)100%110%
File 1: SetItem(...)100%110%
File 1: DeepClone()100%110%
File 1: GetValueKind()100%11100%
File 1: GetPropertyName()0%220%
File 1: GetElementIndex()0%220%
File 1: DeepEquals(...)50%4455.55%
File 1: ReplaceWith(...)0%440%
File 1: AssignParent(...)0%660%
File 1: ConvertFromValue(...)0%880%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Implicit(...)100%110%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 2: op_Explicit(...)100%110%
File 2: op_Explicit(...)0%220%
File 3: Parse(...)100%110%
File 3: Parse(...)100%110%
File 3: Parse(...)100%110%
File 3: Parse(...)100%110%
File 3: ParseAsync()100%110%
File 4: ToJsonString(...)0%220%
File 4: ToString()0%10100%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonNode.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics;
 6using System.Diagnostics.CodeAnalysis;
 7using System.Text.Json.Serialization.Converters;
 8using System.Text.Json.Serialization.Metadata;
 9
 10namespace System.Text.Json.Nodes
 11{
 12    /// <summary>
 13    ///   The base class that represents a single node within a mutable JSON document.
 14    /// </summary>
 15    /// <seealso cref="JsonSerializerOptions.UnknownTypeHandling"/> to specify that a type
 16    /// declared as an <see cref="object"/> should be deserialized as a <see cref="JsonNode"/>.
 17    public abstract partial class JsonNode
 18    {
 19        // Default options instance used when calling built-in JsonNode converters.
 020        private protected static readonly JsonSerializerOptions s_defaultOptions = new();
 21
 22        private JsonNode? _parent;
 23        private JsonNodeOptions? _options;
 24
 25        /// <summary>
 26        /// The underlying JsonElement if the node is backed by a JsonElement.
 27        /// </summary>
 2828        internal virtual JsonElement? UnderlyingElement => null;
 29
 30        /// <summary>
 31        ///   Options to control the behavior.
 32        /// </summary>
 33        public JsonNodeOptions? Options
 34        {
 35            get
 036            {
 037                if (!_options.HasValue && Parent != null)
 038                {
 39                    // Remember the parent options; if node is re-parented later we still want to keep the
 40                    // original options since they may have affected the way the node was created as is the case
 41                    // with JsonObject's case-insensitive dictionary.
 042                    _options = Parent.Options;
 043                }
 44
 045                return _options;
 046            }
 47        }
 48
 65249        internal JsonNode(JsonNodeOptions? options = null)
 65250        {
 65251            _options = options;
 65252        }
 53
 54        /// <summary>
 55        ///   Casts to the derived <see cref="JsonArray"/> type.
 56        /// </summary>
 57        /// <returns>
 58        ///   A <see cref="JsonArray"/>.
 59        /// </returns>
 60        /// <exception cref="InvalidOperationException">
 61        ///   The node is not a <see cref="JsonArray"/>.
 62        /// </exception>
 63        public JsonArray AsArray()
 064        {
 065            JsonArray? jArray = this as JsonArray;
 66
 067            if (jArray is null)
 068            {
 069                ThrowHelper.ThrowInvalidOperationException_NodeWrongType(nameof(JsonArray));
 70            }
 71
 072            return jArray;
 073        }
 74
 75        /// <summary>
 76        ///   Casts to the derived <see cref="JsonObject"/> type.
 77        /// </summary>
 78        /// <returns>
 79        ///   A <see cref="JsonObject"/>.
 80        /// </returns>
 81        /// <exception cref="InvalidOperationException">
 82        ///   The node is not a <see cref="JsonObject"/>.
 83        /// </exception>
 84        public JsonObject AsObject()
 085        {
 086            JsonObject? jObject = this as JsonObject;
 87
 088            if (jObject is null)
 089            {
 090                ThrowHelper.ThrowInvalidOperationException_NodeWrongType(nameof(JsonObject));
 91            }
 92
 093            return jObject;
 094        }
 95
 96        /// <summary>
 97        ///   Casts to the derived <see cref="JsonValue"/> type.
 98        /// </summary>
 99        /// <returns>
 100        ///   A <see cref="JsonValue"/>.
 101        /// </returns>
 102        /// <exception cref="InvalidOperationException">
 103        ///   The node is not a <see cref="JsonValue"/>.
 104        /// </exception>
 105        public JsonValue AsValue()
 0106        {
 0107            JsonValue? jValue = this as JsonValue;
 108
 0109            if (jValue is null)
 0110            {
 0111                ThrowHelper.ThrowInvalidOperationException_NodeWrongType(nameof(JsonValue));
 112            }
 113
 0114            return jValue;
 0115        }
 116
 117        /// <summary>
 118        ///   Gets the parent <see cref="JsonNode"/>.
 119        ///   If there is no parent, <see langword="null"/> is returned.
 120        ///   A parent can either be a <see cref="JsonObject"/> or a <see cref="JsonArray"/>.
 121        /// </summary>
 122        public JsonNode? Parent
 123        {
 124            get
 0125            {
 0126                return _parent;
 0127            }
 128            internal set
 0129            {
 0130                _parent = value;
 0131            }
 132        }
 133
 134        /// <summary>
 135        ///   Gets the JSON path.
 136        /// </summary>
 137        /// <returns>The JSON Path value.</returns>
 138        public string GetPath()
 0139        {
 0140            if (Parent == null)
 0141            {
 0142                return "$";
 143            }
 144
 0145            var path = new ValueStringBuilder(stackalloc char[JsonConstants.StackallocCharThreshold]);
 0146            path.Append('$');
 0147            GetPath(ref path, null);
 0148            return path.ToString();
 0149        }
 150
 151        internal abstract void GetPath(ref ValueStringBuilder path, JsonNode? child);
 152
 153        /// <summary>
 154        ///   Gets the root <see cref="JsonNode"/>.
 155        /// </summary>
 156        /// <remarks>
 157        ///   The current node is returned if it is a root.
 158        /// </remarks>
 159        public JsonNode Root
 160        {
 161            get
 0162            {
 0163                JsonNode? parent = Parent;
 0164                if (parent == null)
 0165                {
 0166                    return this;
 167                }
 168
 0169                while (parent.Parent != null)
 0170                {
 0171                    parent = parent.Parent;
 0172                }
 173
 0174                return parent;
 0175            }
 176        }
 177
 178        /// <summary>
 179        ///   Gets the value for the current <see cref="JsonValue"/>.
 180        /// </summary>
 181        /// <typeparam name="T">The type of the value to obtain from the <see cref="JsonValue"/>.</typeparam>
 182        /// <returns>A value converted from the <see cref="JsonValue"/> instance.</returns>
 183        /// <remarks>
 184        ///   {T} can be the type or base type of the underlying value.
 185        ///   If the underlying value is a <see cref="JsonElement"/> then {T} can also be the type of any primitive
 186        ///   value supported by current <see cref="JsonElement"/>.
 187        ///   Specifying the <see cref="object"/> type for {T} will always succeed and return the underlying value as <s
 188        ///   The underlying value of a <see cref="JsonValue"/> after deserialization is an instance of <see cref="JsonE
 189        ///   otherwise it's the value specified when the <see cref="JsonValue"/> was created.
 190        /// </remarks>
 191        /// <seealso cref="System.Text.Json.Nodes.JsonValue.TryGetValue"></seealso>
 192        /// <exception cref="FormatException">
 193        ///   The current <see cref="JsonNode"/> cannot be represented as a {T}.
 194        /// </exception>
 195        /// <exception cref="InvalidOperationException">
 196        ///   The current <see cref="JsonNode"/> is not a <see cref="JsonValue"/> or
 197        ///   is not compatible with {T}.
 198        /// </exception>
 199        public virtual T GetValue<T>() =>
 0200            throw new InvalidOperationException(SR.Format(SR.NodeWrongType, nameof(JsonValue)));
 201
 202        /// <summary>
 203        ///   Gets or sets the element at the specified index.
 204        /// </summary>
 205        /// <param name="index">The zero-based index of the element to get or set.</param>
 206        /// <exception cref="ArgumentOutOfRangeException">
 207        ///   <paramref name="index"/> is less than 0 or <paramref name="index"/> is greater than the number of properti
 208        /// </exception>
 209        /// <exception cref="InvalidOperationException">
 210        ///   The current <see cref="JsonNode"/> is not a <see cref="JsonArray"/> or <see cref="JsonObject"/>.
 211        /// </exception>
 212        public JsonNode? this[int index]
 213        {
 0214            get => GetItem(index);
 0215            set => SetItem(index, value);
 216        }
 217
 218        private protected virtual JsonNode? GetItem(int index)
 0219        {
 0220            ThrowHelper.ThrowInvalidOperationException_NodeWrongType(nameof(JsonArray), nameof(JsonObject));
 221            return null;
 222        }
 223
 224        private protected virtual void SetItem(int index, JsonNode? node) =>
 0225            ThrowHelper.ThrowInvalidOperationException_NodeWrongType(nameof(JsonArray), nameof(JsonObject));
 226
 227        /// <summary>
 228        ///   Gets or sets the element with the specified property name.
 229        ///   If the property is not found, <see langword="null"/> is returned.
 230        /// </summary>
 231        /// <param name="propertyName">The name of the property to return.</param>
 232        /// <exception cref="ArgumentNullException">
 233        ///   <paramref name="propertyName"/> is <see langword="null"/>.
 234        /// </exception>
 235        /// <exception cref="InvalidOperationException">
 236        ///   The current <see cref="JsonNode"/> is not a <see cref="JsonObject"/>.
 237        /// </exception>
 238        public JsonNode? this[string propertyName]
 239        {
 240            get
 0241            {
 0242                return AsObject().GetItem(propertyName);
 0243            }
 244            set
 0245            {
 0246                AsObject().SetItem(propertyName, value);
 0247            }
 248        }
 249
 250        /// <summary>
 251        /// Creates a new instance of the <see cref="JsonNode"/>. All children nodes are recursively cloned.
 252        /// </summary>
 253        /// <returns>A new cloned instance of the current node.</returns>
 0254        public JsonNode DeepClone() => DeepCloneCore();
 255
 256        internal abstract JsonNode DeepCloneCore();
 257
 258        /// <summary>
 259        /// Returns <see cref="JsonValueKind"/> of current instance.
 260        /// </summary>
 28261        public JsonValueKind GetValueKind() => GetValueKindCore();
 262
 263        private protected abstract JsonValueKind GetValueKindCore();
 264
 265        /// <summary>
 266        /// Returns property name of the current node from the parent object.
 267        /// </summary>
 268        /// <exception cref="InvalidOperationException">
 269        /// The current parent is not a <see cref="JsonObject"/>.
 270        /// </exception>
 271        public string GetPropertyName()
 0272        {
 0273            JsonObject? parentObject = _parent as JsonObject;
 274
 0275            if (parentObject is null)
 0276            {
 0277                ThrowHelper.ThrowInvalidOperationException_NodeParentWrongType(nameof(JsonObject));
 278            }
 279
 0280            return parentObject.GetPropertyName(this);
 0281        }
 282
 283        /// <summary>
 284        /// Returns index of the current node from the parent <see cref="JsonArray" />.
 285        /// </summary>
 286        /// <exception cref="InvalidOperationException">
 287        /// The current parent is not a <see cref="JsonArray"/>.
 288        /// </exception>
 289        public int GetElementIndex()
 0290        {
 0291            JsonArray? parentArray = _parent as JsonArray;
 292
 0293            if (parentArray is null)
 0294            {
 0295                ThrowHelper.ThrowInvalidOperationException_NodeParentWrongType(nameof(JsonArray));
 296            }
 297
 0298            return parentArray.GetElementIndex(this);
 0299        }
 300
 301        /// <summary>
 302        /// Compares the values of two nodes, including the values of all descendant nodes.
 303        /// </summary>
 304        /// <param name="node1">The <see cref="JsonNode"/> to compare.</param>
 305        /// <param name="node2">The <see cref="JsonNode"/> to compare.</param>
 306        /// <returns><c>true</c> if the tokens are equal; otherwise <c>false</c>.</returns>
 307        public static bool DeepEquals(JsonNode? node1, JsonNode? node2)
 14308        {
 14309            if (node1 is null)
 0310            {
 0311                return node2 is null;
 312            }
 14313            else if (node2 is null)
 0314            {
 0315                return false;
 316            }
 317
 14318            return node1.DeepEqualsCore(node2);
 14319        }
 320
 321        internal abstract bool DeepEqualsCore(JsonNode node);
 322
 323        /// <summary>
 324        /// Replaces this node with a new value.
 325        /// </summary>
 326        /// <typeparam name="T">The type of value to be replaced.</typeparam>
 327        /// <param name="value">Value that replaces this node.</param>
 328        [RequiresUnreferencedCode(JsonValue.CreateUnreferencedCodeMessage)]
 329        [RequiresDynamicCode(JsonValue.CreateDynamicCodeMessage)]
 330        public void ReplaceWith<T>(T value)
 0331        {
 332            JsonNode? node;
 0333            switch (_parent)
 334            {
 335                case JsonObject jsonObject:
 0336                    node = ConvertFromValue(value);
 0337                    jsonObject.SetItem(GetPropertyName(), node);
 0338                    return;
 339                case JsonArray jsonArray:
 0340                    node = ConvertFromValue(value);
 0341                    jsonArray.SetItem(GetElementIndex(), node);
 0342                    return;
 343            }
 0344        }
 345
 346        internal void AssignParent(JsonNode parent)
 0347        {
 0348            if (Parent != null)
 0349            {
 0350                ThrowHelper.ThrowInvalidOperationException_NodeAlreadyHasParent();
 351            }
 352
 0353            JsonNode? p = parent;
 0354            while (p != null)
 0355            {
 0356                if (p == this)
 0357                {
 0358                    ThrowHelper.ThrowInvalidOperationException_NodeCycleDetected();
 359                }
 360
 0361                p = p.Parent;
 0362            }
 363
 0364            Parent = parent;
 0365        }
 366
 367        /// <summary>
 368        /// Adaptation of the equivalent JsonValue.Create factory method extended
 369        /// to support arbitrary <see cref="JsonElement"/> and <see cref="JsonNode"/> values.
 370        /// TODO consider making public cf. https://github.com/dotnet/runtime/issues/70427
 371        /// </summary>
 372        [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)]
 373        [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
 374        internal static JsonNode? ConvertFromValue<T>(T? value, JsonNodeOptions? options = null)
 0375        {
 0376            if (value is null)
 0377            {
 0378                return null;
 379            }
 380
 0381            if (value is JsonNode node)
 0382            {
 0383                return node;
 384            }
 385
 0386            if (value is JsonElement element)
 0387            {
 0388                return JsonNodeConverter.Create(element, options);
 389            }
 390
 0391            var jsonTypeInfo = JsonSerializerOptions.Default.GetTypeInfo<T>();
 0392            return JsonValue.CreateFromTypeInfo(value, jsonTypeInfo, options);
 0393        }
 394    }
 395}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonNode.Operators.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5
 6namespace System.Text.Json.Nodes
 7{
 8    public partial class JsonNode
 9    {
 10        /// <summary>
 11        ///   Defines an implicit conversion of a given <see cref="bool"/> to a <see cref="JsonNode"/>.
 12        /// </summary>
 13        /// <param name="value">A <see cref="bool"/> to implicitly convert.</param>
 14        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 015        public static implicit operator JsonNode(bool value) => JsonValue.Create(value);
 16
 17        /// <summary>
 18        ///   Defines an implicit conversion of a given <see cref="bool"/> to a <see cref="JsonNode"/>.
 19        /// </summary>
 20        /// <param name="value">A <see cref="bool"/> to implicitly convert.</param>
 21        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 022        public static implicit operator JsonNode?(bool? value) => JsonValue.Create(value);
 23
 24        /// <summary>
 25        ///   Defines an implicit conversion of a given <see cref="byte"/> to a <see cref="JsonNode"/>.
 26        /// </summary>
 27        /// <param name="value">A <see cref="byte"/> to implicitly convert.</param>
 28        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 029        public static implicit operator JsonNode(byte value) => JsonValue.Create(value);
 30
 31        /// <summary>
 32        ///   Defines an implicit conversion of a given <see cref="byte"/> to a <see cref="JsonNode"/>.
 33        /// </summary>
 34        /// <param name="value">A <see cref="byte"/> to implicitly convert.</param>
 35        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 036        public static implicit operator JsonNode?(byte? value) => JsonValue.Create(value);
 37
 38        /// <summary>
 39        ///   Defines an implicit conversion of a given <see cref="char"/> to a <see cref="JsonNode"/>.
 40        /// </summary>
 41        /// <param name="value">A <see cref="char"/> to implicitly convert.</param>
 42        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 043        public static implicit operator JsonNode(char value) => JsonValue.Create(value);
 44
 45        /// <summary>
 46        ///   Defines an implicit conversion of a given <see cref="char"/> to a <see cref="JsonNode"/>.
 47        /// </summary>
 48        /// <param name="value">A <see cref="char"/> to implicitly convert.</param>
 49        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 050        public static implicit operator JsonNode?(char? value) => JsonValue.Create(value);
 51
 52        /// <summary>
 53        ///   Defines an implicit conversion of a given <see cref="DateTime"/> to a <see cref="JsonNode"/>.
 54        /// </summary>
 55        /// <param name="value">A <see cref="DateTime"/> to implicitly convert.</param>
 56        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 057        public static implicit operator JsonNode(DateTime value) => JsonValue.Create(value);
 58
 59        /// <summary>
 60        ///   Defines an implicit conversion of a given <see cref="DateTime"/> to a <see cref="JsonNode"/>.
 61        /// </summary>
 62        /// <param name="value">A <see cref="DateTime"/> to implicitly convert.</param>
 63        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 064        public static implicit operator JsonNode?(DateTime? value) => JsonValue.Create(value);
 65
 66        /// <summary>
 67        ///   Defines an implicit conversion of a given <see cref="DateTimeOffset"/> to a <see cref="JsonNode"/>.
 68        /// </summary>
 69        /// <param name="value">A <see cref="DateTimeOffset"/> to implicitly convert.</param>
 70        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 071        public static implicit operator JsonNode(DateTimeOffset value) => JsonValue.Create(value);
 72
 73        /// <summary>
 74        ///   Defines an implicit conversion of a given <see cref="DateTimeOffset"/> to a <see cref="JsonNode"/>.
 75        /// </summary>
 76        /// <param name="value">A <see cref="DateTimeOffset"/> to implicitly convert.</param>
 77        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 078        public static implicit operator JsonNode?(DateTimeOffset? value) => JsonValue.Create(value);
 79
 80        /// <summary>
 81        ///   Defines an implicit conversion of a given <see cref="decimal"/> to a <see cref="JsonNode"/>.
 82        /// </summary>
 83        /// <param name="value">A <see cref="decimal"/> to implicitly convert.</param>
 84        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 085        public static implicit operator JsonNode(decimal value) => JsonValue.Create(value);
 86
 87        /// <summary>
 88        ///   Defines an implicit conversion of a given <see cref="decimal"/> to a <see cref="JsonNode"/>.
 89        /// </summary>
 90        /// <param name="value">A <see cref="decimal"/> to implicitly convert.</param>
 91        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 092        public static implicit operator JsonNode?(decimal? value) => JsonValue.Create(value);
 93
 94        /// <summary>
 95        ///   Defines an implicit conversion of a given <see cref="double"/> to a <see cref="JsonNode"/>.
 96        /// </summary>
 97        /// <param name="value">A <see cref="double"/> to implicitly convert.</param>
 98        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 099        public static implicit operator JsonNode(double value) => JsonValue.Create(value);
 100
 101        /// <summary>
 102        ///   Defines an implicit conversion of a given <see cref="double"/> to a <see cref="JsonNode"/>.
 103        /// </summary>
 104        /// <param name="value">A <see cref="double"/> to implicitly convert.</param>
 105        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0106        public static implicit operator JsonNode?(double? value) => JsonValue.Create(value);
 107
 108        /// <summary>
 109        ///   Defines an implicit conversion of a given <see cref="Guid"/> to a <see cref="JsonNode"/>.
 110        /// </summary>
 111        /// <param name="value">A <see cref="Guid"/> to implicitly convert.</param>
 112        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0113        public static implicit operator JsonNode(Guid value) => JsonValue.Create(value);
 114
 115        /// <summary>
 116        ///   Defines an implicit conversion of a given <see cref="Guid"/> to a <see cref="JsonNode"/>.
 117        /// </summary>
 118        /// <param name="value">A <see cref="Guid"/> to implicitly convert.</param>
 119        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0120        public static implicit operator JsonNode?(Guid? value) => JsonValue.Create(value);
 121
 122        /// <summary>
 123        ///   Defines an implicit conversion of a given <see cref="short"/> to a <see cref="JsonNode"/>.
 124        /// </summary>
 125        /// <param name="value">A <see cref="short"/> to implicitly convert.</param>
 126        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0127        public static implicit operator JsonNode(short value) => JsonValue.Create(value);
 128
 129        /// <summary>
 130        ///   Defines an implicit conversion of a given <see cref="short"/> to a <see cref="JsonNode"/>.
 131        /// </summary>
 132        /// <param name="value">A <see cref="short"/> to implicitly convert.</param>
 133        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0134        public static implicit operator JsonNode?(short? value) => JsonValue.Create(value);
 135
 136        /// <summary>
 137        ///   Defines an implicit conversion of a given <see cref="int"/> to a <see cref="JsonNode"/>.
 138        /// </summary>
 139        /// <param name="value">A <see cref="int"/> to implicitly convert.</param>
 140        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0141        public static implicit operator JsonNode(int value) => JsonValue.Create(value);
 142
 143        /// <summary>
 144        ///   Defines an implicit conversion of a given <see cref="int"/> to a <see cref="JsonNode"/>.
 145        /// </summary>
 146        /// <param name="value">A <see cref="int"/> to implicitly convert.</param>
 147        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0148        public static implicit operator JsonNode?(int? value) => JsonValue.Create(value);
 149
 150        /// <summary>
 151        ///   Defines an implicit conversion of a given <see cref="long"/> to a <see cref="JsonNode"/>.
 152        /// </summary>
 153        /// <param name="value">A <see cref="long"/> to implicitly convert.</param>
 154        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0155        public static implicit operator JsonNode(long value) => JsonValue.Create(value);
 156
 157        /// <summary>
 158        ///   Defines an implicit conversion of a given <see cref="long"/> to a <see cref="JsonNode"/>.
 159        /// </summary>
 160        /// <param name="value">A <see cref="long"/> to implicitly convert.</param>
 161        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0162        public static implicit operator JsonNode?(long? value) => JsonValue.Create(value);
 163
 164        /// <summary>
 165        ///   Defines an implicit conversion of a given <see cref="sbyte"/> to a <see cref="JsonNode"/>.
 166        /// </summary>
 167        /// <param name="value">A <see cref="sbyte"/> to implicitly convert.</param>
 168        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 169        [System.CLSCompliantAttribute(false)]
 0170        public static implicit operator JsonNode(sbyte value) => JsonValue.Create(value);
 171
 172        /// <summary>
 173        ///   Defines an implicit conversion of a given <see cref="sbyte"/> to a <see cref="JsonNode"/>.
 174        /// </summary>
 175        /// <param name="value">A <see cref="sbyte"/> to implicitly convert.</param>
 176        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 177        [System.CLSCompliantAttribute(false)]
 0178        public static implicit operator JsonNode?(sbyte? value) => JsonValue.Create(value);
 179
 180        /// <summary>
 181        ///   Defines an implicit conversion of a given <see cref="float"/> to a <see cref="JsonNode"/>.
 182        /// </summary>
 183        /// <param name="value">A <see cref="float"/> to implicitly convert.</param>
 184        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0185        public static implicit operator JsonNode(float value) => JsonValue.Create(value);
 186
 187        /// <summary>
 188        ///   Defines an implicit conversion of a given <see cref="float"/> to a <see cref="JsonNode"/>.
 189        /// </summary>
 190        /// <param name="value">A <see cref="float"/> to implicitly convert.</param>
 191        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 0192        public static implicit operator JsonNode?(float? value) => JsonValue.Create(value);
 193
 194        /// <summary>
 195        ///   Defines an implicit conversion of a given <see cref="string"/> to a <see cref="JsonNode"/>.
 196        /// </summary>
 197        /// <param name="value">A <see cref="string"/> to implicitly convert.</param>
 198        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 199        [return: NotNullIfNotNull(nameof(value))]
 0200        public static implicit operator JsonNode?(string? value) => JsonValue.Create(value);
 201
 202        /// <summary>
 203        ///   Defines an implicit conversion of a given <see cref="ushort"/> to a <see cref="JsonNode"/>.
 204        /// </summary>
 205        /// <param name="value">A <see cref="ushort"/> to implicitly convert.</param>
 206        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 207        [System.CLSCompliantAttribute(false)]
 0208        public static implicit operator JsonNode(ushort value) => JsonValue.Create(value);
 209
 210        /// <summary>
 211        ///   Defines an implicit conversion of a given <see cref="ushort"/> to a <see cref="JsonNode"/>.
 212        /// </summary>
 213        /// <param name="value">A <see cref="ushort"/> to implicitly convert.</param>
 214        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 215        [System.CLSCompliantAttribute(false)]
 0216        public static implicit operator JsonNode?(ushort? value) => JsonValue.Create(value);
 217
 218        /// <summary>
 219        ///   Defines an implicit conversion of a given <see cref="uint"/> to a <see cref="JsonNode"/>.
 220        /// </summary>
 221        /// <param name="value">A <see cref="uint"/> to implicitly convert.</param>
 222        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 223        [System.CLSCompliantAttribute(false)]
 0224        public static implicit operator JsonNode(uint value) => JsonValue.Create(value);
 225
 226        /// <summary>
 227        ///   Defines an implicit conversion of a given <see cref="uint"/> to a <see cref="JsonNode"/>.
 228        /// </summary>
 229        /// <param name="value">A <see cref="uint"/> to implicitly convert.</param>
 230        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 231        [System.CLSCompliantAttribute(false)]
 0232        public static implicit operator JsonNode?(uint? value) => JsonValue.Create(value);
 233
 234        /// <summary>
 235        ///   Defines an implicit conversion of a given <see cref="ulong"/> to a <see cref="JsonNode"/>.
 236        /// </summary>
 237        /// <param name="value">A <see cref="ulong"/> to implicitly convert.</param>
 238        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 239        [System.CLSCompliantAttribute(false)]
 0240        public static implicit operator JsonNode(ulong value) => JsonValue.Create(value);
 241
 242        /// <summary>
 243        ///   Defines an implicit conversion of a given <see cref="ulong"/> to a <see cref="JsonNode"/>.
 244        /// </summary>
 245        /// <param name="value">A <see cref="ulong"/> to implicitly convert.</param>
 246        /// <returns>A <see cref="JsonNode"/> instance converted from the <paramref name="value"/> parameter.</returns>
 247        [System.CLSCompliantAttribute(false)]
 0248        public static implicit operator JsonNode?(ulong? value) => JsonValue.Create(value);
 249
 250        /// <summary>
 251        ///   Defines an explicit conversion of a given <see cref="bool"/> to a <see cref="JsonNode"/>.
 252        /// </summary>
 253        /// <param name="value">A <see cref="bool"/> to explicitly convert.</param>
 254        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0255        public static explicit operator bool(JsonNode value) => value.GetValue<bool>();
 256
 257        /// <summary>
 258        ///   Defines an explicit conversion of a given <see cref="bool"/> to a <see cref="JsonNode"/>.
 259        /// </summary>
 260        /// <param name="value">A <see cref="bool"/> to explicitly convert.</param>
 261        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0262        public static explicit operator bool?(JsonNode? value) => value?.GetValue<bool>();
 263
 264        /// <summary>
 265        ///   Defines an explicit conversion of a given <see cref="byte"/> to a <see cref="JsonNode"/>.
 266        /// </summary>
 267        /// <param name="value">A <see cref="byte"/> to explicitly convert.</param>
 268        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0269        public static explicit operator byte(JsonNode value) => value.GetValue<byte>();
 270
 271        /// <summary>
 272        ///   Defines an explicit conversion of a given <see cref="byte"/> to a <see cref="JsonNode"/>.
 273        /// </summary>
 274        /// <param name="value">A <see cref="byte"/> to explicitly convert.</param>
 275        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0276        public static explicit operator byte?(JsonNode? value) => value?.GetValue<byte>();
 277
 278        /// <summary>
 279        ///   Defines an explicit conversion of a given <see cref="char"/> to a <see cref="JsonNode"/>.
 280        /// </summary>
 281        /// <param name="value">A <see cref="char"/> to explicitly convert.</param>
 282        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0283        public static explicit operator char(JsonNode value) => value.GetValue<char>();
 284
 285        /// <summary>
 286        ///   Defines an explicit conversion of a given <see cref="char"/> to a <see cref="JsonNode"/>.
 287        /// </summary>
 288        /// <param name="value">A <see cref="char"/> to explicitly convert.</param>
 289        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0290        public static explicit operator char?(JsonNode? value) => value?.GetValue<char>();
 291
 292        /// <summary>
 293        ///   Defines an explicit conversion of a given <see cref="DateTime"/> to a <see cref="JsonNode"/>.
 294        /// </summary>
 295        /// <param name="value">A <see cref="DateTime"/> to explicitly convert.</param>
 296        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0297        public static explicit operator DateTime(JsonNode value) => value.GetValue<DateTime>();
 298
 299        /// <summary>
 300        ///   Defines an explicit conversion of a given <see cref="DateTime"/> to a <see cref="JsonNode"/>.
 301        /// </summary>
 302        /// <param name="value">A <see cref="DateTime"/> to explicitly convert.</param>
 303        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0304        public static explicit operator DateTime?(JsonNode? value) => value?.GetValue<DateTime>();
 305
 306        /// <summary>
 307        ///   Defines an explicit conversion of a given <see cref="DateTimeOffset"/> to a <see cref="JsonNode"/>.
 308        /// </summary>
 309        /// <param name="value">A <see cref="DateTimeOffset"/> to explicitly convert.</param>
 310        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0311        public static explicit operator DateTimeOffset(JsonNode value) => value.GetValue<DateTimeOffset>();
 312
 313        /// <summary>
 314        ///   Defines an explicit conversion of a given <see cref="DateTimeOffset"/> to a <see cref="JsonNode"/>.
 315        /// </summary>
 316        /// <param name="value">A <see cref="DateTimeOffset"/> to explicitly convert.</param>
 317        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0318        public static explicit operator DateTimeOffset?(JsonNode? value) => value?.GetValue<DateTimeOffset>();
 319
 320        /// <summary>
 321        ///   Defines an explicit conversion of a given <see cref="decimal"/> to a <see cref="JsonNode"/>.
 322        /// </summary>
 323        /// <param name="value">A <see cref="decimal"/> to explicitly convert.</param>
 324        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0325        public static explicit operator decimal(JsonNode value) => value.GetValue<decimal>();
 326
 327        /// <summary>
 328        ///   Defines an explicit conversion of a given <see cref="decimal"/> to a <see cref="JsonNode"/>.
 329        /// </summary>
 330        /// <param name="value">A <see cref="decimal"/> to explicitly convert.</param>
 331        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0332        public static explicit operator decimal?(JsonNode? value) => value?.GetValue<decimal>();
 333
 334        /// <summary>
 335        ///   Defines an explicit conversion of a given <see cref="double"/> to a <see cref="JsonNode"/>.
 336        /// </summary>
 337        /// <param name="value">A <see cref="double"/> to explicitly convert.</param>
 338        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0339        public static explicit operator double(JsonNode value) => value.GetValue<double>();
 340
 341        /// <summary>
 342        ///   Defines an explicit conversion of a given <see cref="double"/> to a <see cref="JsonNode"/>.
 343        /// </summary>
 344        /// <param name="value">A <see cref="double"/> to explicitly convert.</param>
 345        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0346        public static explicit operator double?(JsonNode? value) => value?.GetValue<double>();
 347
 348        /// <summary>
 349        ///   Defines an explicit conversion of a given <see cref="Guid"/> to a <see cref="JsonNode"/>.
 350        /// </summary>
 351        /// <param name="value">A <see cref="Guid"/> to explicitly convert.</param>
 352        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0353        public static explicit operator Guid(JsonNode value) => value.GetValue<Guid>();
 354
 355        /// <summary>
 356        ///   Defines an explicit conversion of a given <see cref="Guid"/> to a <see cref="JsonNode"/>.
 357        /// </summary>
 358        /// <param name="value">A <see cref="Guid"/> to explicitly convert.</param>
 359        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0360        public static explicit operator Guid?(JsonNode? value) => value?.GetValue<Guid>();
 361
 362        /// <summary>
 363        ///   Defines an explicit conversion of a given <see cref="short"/> to a <see cref="JsonNode"/>.
 364        /// </summary>
 365        /// <param name="value">A <see cref="short"/> to explicitly convert.</param>
 366        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0367        public static explicit operator short(JsonNode value) => value.GetValue<short>();
 368
 369        /// <summary>
 370        ///   Defines an explicit conversion of a given <see cref="short"/> to a <see cref="JsonNode"/>.
 371        /// </summary>
 372        /// <param name="value">A <see cref="short"/> to explicitly convert.</param>
 373        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0374        public static explicit operator short?(JsonNode? value) => value?.GetValue<short>();
 375
 376        /// <summary>
 377        ///   Defines an explicit conversion of a given <see cref="int"/> to a <see cref="JsonNode"/>.
 378        /// </summary>
 379        /// <param name="value">A <see cref="int"/> to explicitly convert.</param>
 380        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0381        public static explicit operator int(JsonNode value) => value.GetValue<int>();
 382
 383        /// <summary>
 384        ///   Defines an explicit conversion of a given <see cref="int"/> to a <see cref="JsonNode"/>.
 385        /// </summary>
 386        /// <param name="value">A <see cref="int"/> to explicitly convert.</param>
 387        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0388        public static explicit operator int?(JsonNode? value) => value?.GetValue<int>();
 389
 390        /// <summary>
 391        ///   Defines an explicit conversion of a given <see cref="long"/> to a <see cref="JsonNode"/>.
 392        /// </summary>
 393        /// <param name="value">A <see cref="long"/> to explicitly convert.</param>
 394        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0395        public static explicit operator long(JsonNode value) => value.GetValue<long>();
 396
 397        /// <summary>
 398        ///   Defines an explicit conversion of a given <see cref="long"/> to a <see cref="JsonNode"/>.
 399        /// </summary>
 400        /// <param name="value">A <see cref="long"/> to explicitly convert.</param>
 401        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0402        public static explicit operator long?(JsonNode? value) => value?.GetValue<long>();
 403
 404        /// <summary>
 405        ///   Defines an explicit conversion of a given <see cref="sbyte"/> to a <see cref="JsonNode"/>.
 406        /// </summary>
 407        /// <param name="value">A <see cref="sbyte"/> to explicitly convert.</param>
 408        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 409        [System.CLSCompliantAttribute(false)]
 0410        public static explicit operator sbyte(JsonNode value) => value.GetValue<sbyte>();
 411
 412        /// <summary>
 413        ///   Defines an explicit conversion of a given <see cref="sbyte"/> to a <see cref="JsonNode"/>.
 414        /// </summary>
 415        /// <param name="value">A <see cref="sbyte"/> to explicitly convert.</param>
 416        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 417        [System.CLSCompliantAttribute(false)]
 0418        public static explicit operator sbyte?(JsonNode? value) => value?.GetValue<sbyte>();
 419
 420        /// <summary>
 421        ///   Defines an explicit conversion of a given <see cref="float"/> to a <see cref="JsonNode"/>.
 422        /// </summary>
 423        /// <param name="value">A <see cref="float"/> to explicitly convert.</param>
 424        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0425        public static explicit operator float(JsonNode value) => value.GetValue<float>();
 426
 427        /// <summary>
 428        ///   Defines an explicit conversion of a given <see cref="float"/> to a <see cref="JsonNode"/>.
 429        /// </summary>
 430        /// <param name="value">A <see cref="float"/> to explicitly convert.</param>
 431        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0432        public static explicit operator float?(JsonNode? value) => value?.GetValue<float>();
 433
 434        /// <summary>
 435        ///   Defines an explicit conversion of a given <see cref="string"/> to a <see cref="JsonNode"/>.
 436        /// </summary>
 437        /// <param name="value">A <see cref="string"/> to explicitly convert.</param>
 438        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 0439        public static explicit operator string?(JsonNode? value) => value?.GetValue<string>();
 440
 441        /// <summary>
 442        ///   Defines an explicit conversion of a given <see cref="ushort"/> to a <see cref="JsonNode"/>.
 443        /// </summary>
 444        /// <param name="value">A <see cref="ushort"/> to explicitly convert.</param>
 445        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 446        [System.CLSCompliantAttribute(false)]
 0447        public static explicit operator ushort(JsonNode value) => value.GetValue<ushort>();
 448
 449        /// <summary>
 450        ///   Defines an explicit conversion of a given <see cref="ushort"/> to a <see cref="JsonNode"/>.
 451        /// </summary>
 452        /// <param name="value">A <see cref="ushort"/> to explicitly convert.</param>
 453        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 454        [System.CLSCompliantAttribute(false)]
 0455        public static explicit operator ushort?(JsonNode? value) => value?.GetValue<ushort>();
 456
 457        /// <summary>
 458        ///   Defines an explicit conversion of a given <see cref="uint"/> to a <see cref="JsonNode"/>.
 459        /// </summary>
 460        /// <param name="value">A <see cref="uint"/> to explicitly convert.</param>
 461        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 462        [System.CLSCompliantAttribute(false)]
 0463        public static explicit operator uint(JsonNode value) => value.GetValue<uint>();
 464
 465        /// <summary>
 466        ///   Defines an explicit conversion of a given <see cref="uint"/> to a <see cref="JsonNode"/>.
 467        /// </summary>
 468        /// <param name="value">A <see cref="uint"/> to explicitly convert.</param>
 469        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 470        [System.CLSCompliantAttribute(false)]
 0471        public static explicit operator uint?(JsonNode? value) => value?.GetValue<uint>();
 472
 473        /// <summary>
 474        ///   Defines an explicit conversion of a given <see cref="ulong"/> to a <see cref="JsonNode"/>.
 475        /// </summary>
 476        /// <param name="value">A <see cref="ulong"/> to explicitly convert.</param>
 477        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 478        [System.CLSCompliantAttribute(false)]
 0479        public static explicit operator ulong(JsonNode value) => value.GetValue<ulong>();
 480
 481        /// <summary>
 482        ///   Defines an explicit conversion of a given <see cref="ulong"/> to a <see cref="JsonNode"/>.
 483        /// </summary>
 484        /// <param name="value">A <see cref="ulong"/> to explicitly convert.</param>
 485        /// <returns>A value converted from the <see cref="JsonNode"/> instance.</returns>
 486        [System.CLSCompliantAttribute(false)]
 0487        public static explicit operator ulong?(JsonNode? value) => value?.GetValue<ulong>();
 488    }
 489}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonNode.Parse.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.IO;
 6using System.Text.Json.Serialization.Converters;
 7using System.Threading;
 8using System.Threading.Tasks;
 9
 10namespace System.Text.Json.Nodes
 11{
 12    public abstract partial class JsonNode
 13    {
 14        /// <summary>
 15        ///   Parses one JSON value (including objects or arrays) from the provided reader.
 16        /// </summary>
 17        /// <param name="reader">The reader to read.</param>
 18        /// <param name="nodeOptions">Options to control the behavior.</param>
 19        /// <returns>
 20        ///   The <see cref="JsonNode"/> from the reader.
 21        /// </returns>
 22        /// <remarks>
 23        ///   <para>
 24        ///     If the <see cref="Utf8JsonReader.TokenType"/> property of <paramref name="reader"/>
 25        ///     is <see cref="JsonTokenType.PropertyName"/> or <see cref="JsonTokenType.None"/>, the
 26        ///     reader will be advanced by one call to <see cref="Utf8JsonReader.Read"/> to determine
 27        ///     the start of the value.
 28        ///   </para>
 29        ///   <para>
 30        ///     Upon completion of this method, <paramref name="reader"/> will be positioned at the
 31        ///     final token in the JSON value.  If an exception is thrown, the reader is reset to the state it was in wh
 32        ///   </para>
 33        ///   <para>
 34        ///     This method makes a copy of the data the reader acted on, so there is no caller
 35        ///     requirement to maintain data integrity beyond the return of this method.
 36        ///   </para>
 37        /// </remarks>
 38        /// <exception cref="ArgumentException">
 39        ///   <paramref name="reader"/> is using unsupported options.
 40        /// </exception>
 41        /// <exception cref="ArgumentException">
 42        ///   The current <paramref name="reader"/> token does not start or represent a value.
 43        /// </exception>
 44        /// <exception cref="JsonException">
 45        ///   A value could not be read from the reader.
 46        /// </exception>
 47        public static JsonNode? Parse(
 48            ref Utf8JsonReader reader,
 49            JsonNodeOptions? nodeOptions = null)
 050        {
 051            JsonElement element = JsonElement.ParseValue(ref reader);
 052            return JsonNodeConverter.Create(element, nodeOptions);
 053        }
 54
 55        /// <summary>
 56        ///   Parses text representing a single JSON value.
 57        /// </summary>
 58        /// <param name="json">JSON text to parse.</param>
 59        /// <param name="nodeOptions">Options to control the node behavior after parsing.</param>
 60        /// <param name="documentOptions">Options to control the document behavior during parsing.</param>
 61        /// <returns>
 62        ///   A <see cref="JsonNode"/> representation of the JSON value.
 63        /// </returns>
 64        /// <exception cref="ArgumentNullException">
 65        ///   <paramref name="json"/> is <see langword="null"/>.
 66        /// </exception>
 67        /// <exception cref="JsonException">
 68        ///   <paramref name="json"/> does not represent a valid single JSON value.
 69        /// </exception>
 70        public static JsonNode? Parse(
 71            [StringSyntax(StringSyntaxAttribute.Json)] string json,
 72            JsonNodeOptions? nodeOptions = null,
 73            JsonDocumentOptions documentOptions = default(JsonDocumentOptions))
 074        {
 075            ArgumentNullException.ThrowIfNull(json);
 76
 077            JsonElement element = JsonElement.Parse(json, documentOptions);
 078            return JsonNodeConverter.Create(element, nodeOptions);
 079        }
 80
 81        /// <summary>
 82        ///   Parses text representing a single JSON value.
 83        /// </summary>
 84        /// <param name="utf8Json">JSON text to parse.</param>
 85        /// <param name="nodeOptions">Options to control the node behavior after parsing.</param>
 86        /// <param name="documentOptions">Options to control the document behavior during parsing.</param>
 87        /// <returns>
 88        ///   A <see cref="JsonNode"/> representation of the JSON value.
 89        /// </returns>
 90        /// <exception cref="JsonException">
 91        ///   <paramref name="utf8Json"/> does not represent a valid single JSON value.
 92        /// </exception>
 93        public static JsonNode? Parse(
 94            ReadOnlySpan<byte> utf8Json,
 95            JsonNodeOptions? nodeOptions = null,
 96            JsonDocumentOptions documentOptions = default(JsonDocumentOptions))
 097        {
 098            JsonElement element = JsonElement.Parse(utf8Json, documentOptions);
 099            return JsonNodeConverter.Create(element, nodeOptions);
 0100        }
 101
 102        /// <summary>
 103        ///   Parse a <see cref="Stream"/> as UTF-8 encoded data representing a single JSON value into a
 104        ///   <see cref="JsonNode"/>.  The Stream will be read to completion.
 105        /// </summary>
 106        /// <param name="utf8Json">JSON text to parse.</param>
 107        /// <param name="nodeOptions">Options to control the node behavior after parsing.</param>
 108        /// <param name="documentOptions">Options to control the document behavior during parsing.</param>
 109        /// <returns>
 110        ///   A <see cref="JsonNode"/> representation of the JSON value.
 111        /// </returns>
 112        /// <exception cref="JsonException">
 113        ///   <paramref name="utf8Json"/> does not represent a valid single JSON value.
 114        /// </exception>
 115        public static JsonNode? Parse(
 116            Stream utf8Json,
 117            JsonNodeOptions? nodeOptions = null,
 118            JsonDocumentOptions documentOptions = default)
 0119        {
 0120            ArgumentNullException.ThrowIfNull(utf8Json);
 121
 0122            JsonElement element = JsonElement.ParseValue(utf8Json, documentOptions);
 0123            return JsonNodeConverter.Create(element, nodeOptions);
 0124        }
 125
 126        /// <summary>
 127        ///   Parse a <see cref="Stream"/> as UTF-8 encoded data representing a single JSON value into a
 128        ///   <see cref="JsonNode"/>.  The Stream will be read to completion.
 129        /// </summary>
 130        /// <param name="utf8Json">JSON text to parse.</param>
 131        /// <param name="nodeOptions">Options to control the node behavior after parsing.</param>
 132        /// <param name="documentOptions">Options to control the document behavior during parsing.</param>
 133        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 134        /// <returns>
 135        ///   A <see cref="Task"/> to produce a <see cref="JsonNode"/> representation of the JSON value.
 136        /// </returns>
 137        /// <exception cref="JsonException">
 138        ///   <paramref name="utf8Json"/> does not represent a valid single JSON value.
 139        /// </exception>
 140        public static async Task<JsonNode?> ParseAsync(
 141            Stream utf8Json,
 142            JsonNodeOptions? nodeOptions = null,
 143            JsonDocumentOptions documentOptions = default,
 144            CancellationToken cancellationToken = default)
 0145        {
 0146            ArgumentNullException.ThrowIfNull(utf8Json);
 147
 0148            JsonDocument document = await JsonDocument.ParseAsyncCoreUnrented(utf8Json, documentOptions, cancellationTok
 0149            return JsonNodeConverter.Create(document.RootElement, nodeOptions);
 0150        }
 151    }
 152}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonNode.To.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.Text.Json.Nodes
 5{
 6    public abstract partial class JsonNode
 7    {
 8        /// <summary>
 9        ///   Converts the current instance to string in JSON format.
 10        /// </summary>
 11        /// <param name="options">Options to control the serialization behavior.</param>
 12        /// <returns>JSON representation of current instance.</returns>
 13        public string ToJsonString(JsonSerializerOptions? options = null)
 014        {
 015            JsonWriterOptions writerOptions = default;
 016            int defaultBufferSize = JsonSerializerOptions.BufferSizeDefault;
 017            if (options is not null)
 018            {
 019                writerOptions = options.GetWriterOptions();
 020                defaultBufferSize = options.DefaultBufferSize;
 021            }
 22
 023            Utf8JsonWriter writer = Utf8JsonWriterCache.RentWriterAndBuffer(writerOptions, defaultBufferSize, out Pooled
 24            try
 025            {
 026                WriteTo(writer, options);
 027                writer.Flush();
 028                return Encoding.UTF8.GetString(output.WrittenSpan);
 29            }
 30            finally
 031            {
 032                Utf8JsonWriterCache.ReturnWriterAndBuffer(writer, output);
 033            }
 034        }
 35
 36        /// <summary>
 37        ///   Gets a string representation for the current value appropriate to the node type.
 38        /// </summary>
 39        /// <returns>A string representation for the current value appropriate to the node type.</returns>
 40        public override string ToString()
 041        {
 42            // Special case for string; don't quote it.
 043            if (this is JsonValue)
 044            {
 045                switch (this)
 46                {
 47                    case JsonValuePrimitive<string> jsonString:
 048                        return jsonString.Value;
 49                    case JsonValueOfElement { Value.ValueKind: JsonValueKind.String } jsonElement:
 050                        return jsonElement.Value.GetString()!;
 51                    case JsonValueOfJsonString jsonValueOfJsonString:
 052                        return jsonValueOfJsonString.GetValue<string>()!;
 53                }
 054            }
 55
 056            Utf8JsonWriter writer = Utf8JsonWriterCache.RentWriterAndBuffer(new JsonWriterOptions { Indented = true }, J
 57            try
 058            {
 059                WriteTo(writer);
 060                writer.Flush();
 061                return Encoding.UTF8.GetString(output.WrittenSpan);
 62            }
 63            finally
 064            {
 065                Utf8JsonWriterCache.ReturnWriterAndBuffer(writer, output);
 066            }
 067        }
 68
 69        /// <summary>
 70        ///   Write the <see cref="JsonNode"/> into the provided <see cref="Utf8JsonWriter"/> as JSON.
 71        /// </summary>
 72        /// <param name="writer">The <see cref="Utf8JsonWriter"/>.</param>
 73        /// <exception cref="ArgumentNullException">
 74        ///   The <paramref name="writer"/> parameter is <see langword="null"/>.
 75        /// </exception>
 76        /// <param name="options">Options to control the serialization behavior.</param>
 77        public abstract void WriteTo(Utf8JsonWriter writer, JsonSerializerOptions? options = null);
 78    }
 79}

Methods/Properties

.cctor()
UnderlyingElement()
Options()
.ctor(System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
AsArray()
AsObject()
AsValue()
Parent()
Parent(System.Text.Json.Nodes.JsonNode)
GetPath()
Root()
GetValue()
Item(System.Int32)
Item(System.Int32,System.Text.Json.Nodes.JsonNode)
GetItem(System.Int32)
SetItem(System.Int32,System.Text.Json.Nodes.JsonNode)
Item(System.String)
Item(System.String,System.Text.Json.Nodes.JsonNode)
DeepClone()
GetValueKind()
GetPropertyName()
GetElementIndex()
DeepEquals(System.Text.Json.Nodes.JsonNode,System.Text.Json.Nodes.JsonNode)
ReplaceWith(T)
AssignParent(System.Text.Json.Nodes.JsonNode)
ConvertFromValue(T,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
op_Implicit(System.Boolean)
op_Implicit(System.Nullable`1<System.Boolean>)
op_Implicit(System.Byte)
op_Implicit(System.Nullable`1<System.Byte>)
op_Implicit(System.Char)
op_Implicit(System.Nullable`1<System.Char>)
op_Implicit(System.DateTime)
op_Implicit(System.Nullable`1<System.DateTime>)
op_Implicit(System.DateTimeOffset)
op_Implicit(System.Nullable`1<System.DateTimeOffset>)
op_Implicit(System.Decimal)
op_Implicit(System.Nullable`1<System.Decimal>)
op_Implicit(System.Double)
op_Implicit(System.Nullable`1<System.Double>)
op_Implicit(System.Guid)
op_Implicit(System.Nullable`1<System.Guid>)
op_Implicit(System.Int16)
op_Implicit(System.Nullable`1<System.Int16>)
op_Implicit(System.Int32)
op_Implicit(System.Nullable`1<System.Int32>)
op_Implicit(System.Int64)
op_Implicit(System.Nullable`1<System.Int64>)
op_Implicit(System.SByte)
op_Implicit(System.Nullable`1<System.SByte>)
op_Implicit(System.Single)
op_Implicit(System.Nullable`1<System.Single>)
op_Implicit(System.String)
op_Implicit(System.UInt16)
op_Implicit(System.Nullable`1<System.UInt16>)
op_Implicit(System.UInt32)
op_Implicit(System.Nullable`1<System.UInt32>)
op_Implicit(System.UInt64)
op_Implicit(System.Nullable`1<System.UInt64>)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
op_Explicit(System.Text.Json.Nodes.JsonNode)
Parse(System.Text.Json.Utf8JsonReader&,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Parse(System.String,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>,System.Text.Json.JsonDocumentOptions)
Parse(System.ReadOnlySpan`1<System.Byte>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>,System.Text.Json.JsonDocumentOptions)
Parse(System.IO.Stream,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>,System.Text.Json.JsonDocumentOptions)
ParseAsync()
ToJsonString(System.Text.Json.JsonSerializerOptions)
ToString()