< Summary

Line coverage
26%
Covered lines: 31
Uncovered lines: 84
Coverable lines: 115
Total lines: 495
Line coverage: 26.9%
Branch coverage
10%
Covered branches: 8
Total branches: 78
Branch coverage: 10.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonValue.CreateOverloads.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.Text.Json.Serialization.Metadata;
 6
 7namespace System.Text.Json.Nodes
 8{
 9    public partial class JsonValue
 10    {
 11        /// <summary>
 12        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 13        /// </summary>
 14        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 15        /// <param name="options">Options to control the behavior.</param>
 16        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 017        public static JsonValue Create(bool value, JsonNodeOptions? options = null) => new JsonValuePrimitive<bool>(valu
 18
 19        /// <summary>
 20        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 21        /// </summary>
 22        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 23        /// <param name="options">Options to control the behavior.</param>
 24        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 025        public static JsonValue? Create(bool? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 26
 27        /// <summary>
 28        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 29        /// </summary>
 30        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 31        /// <param name="options">Options to control the behavior.</param>
 32        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 033        public static JsonValue Create(byte value, JsonNodeOptions? options = null) => new JsonValuePrimitive<byte>(valu
 34
 35        /// <summary>
 36        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 37        /// </summary>
 38        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 39        /// <param name="options">Options to control the behavior.</param>
 40        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 041        public static JsonValue? Create(byte? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 42
 43        /// <summary>
 44        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 45        /// </summary>
 46        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 47        /// <param name="options">Options to control the behavior.</param>
 48        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 049        public static JsonValue Create(char value, JsonNodeOptions? options = null) => new JsonValuePrimitive<char>(valu
 50
 51        /// <summary>
 52        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 53        /// </summary>
 54        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 55        /// <param name="options">Options to control the behavior.</param>
 56        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 057        public static JsonValue? Create(char? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 58
 59        /// <summary>
 60        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 61        /// </summary>
 62        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 63        /// <param name="options">Options to control the behavior.</param>
 64        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 065        public static JsonValue Create(DateTime value, JsonNodeOptions? options = null) => new JsonValuePrimitive<DateTi
 66
 67        /// <summary>
 68        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 69        /// </summary>
 70        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 71        /// <param name="options">Options to control the behavior.</param>
 72        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 073        public static JsonValue? Create(DateTime? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonVa
 74
 75        /// <summary>
 76        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 77        /// </summary>
 78        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 79        /// <param name="options">Options to control the behavior.</param>
 80        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 081        public static JsonValue Create(DateTimeOffset value, JsonNodeOptions? options = null) => new JsonValuePrimitive<
 82
 83        /// <summary>
 84        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 85        /// </summary>
 86        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 87        /// <param name="options">Options to control the behavior.</param>
 88        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 089        public static JsonValue? Create(DateTimeOffset? value, JsonNodeOptions? options = null) => value.HasValue ? new 
 90
 91        /// <summary>
 92        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 93        /// </summary>
 94        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 95        /// <param name="options">Options to control the behavior.</param>
 96        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 097        public static JsonValue Create(decimal value, JsonNodeOptions? options = null) => new JsonValuePrimitive<decimal
 98
 99        /// <summary>
 100        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 101        /// </summary>
 102        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 103        /// <param name="options">Options to control the behavior.</param>
 104        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0105        public static JsonValue? Create(decimal? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonVal
 106
 107        /// <summary>
 108        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 109        /// </summary>
 110        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 111        /// <param name="options">Options to control the behavior.</param>
 112        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0113        public static JsonValue Create(double value, JsonNodeOptions? options = null) => new JsonValuePrimitive<double>(
 114
 115        /// <summary>
 116        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 117        /// </summary>
 118        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 119        /// <param name="options">Options to control the behavior.</param>
 120        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0121        public static JsonValue? Create(double? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValu
 122
 123        /// <summary>
 124        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 125        /// </summary>
 126        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 127        /// <param name="options">Options to control the behavior.</param>
 128        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0129        public static JsonValue Create(Guid value, JsonNodeOptions? options = null) => new JsonValuePrimitive<Guid>(valu
 130
 131        /// <summary>
 132        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 133        /// </summary>
 134        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 135        /// <param name="options">Options to control the behavior.</param>
 136        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0137        public static JsonValue? Create(Guid? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 138
 139        /// <summary>
 140        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 141        /// </summary>
 142        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 143        /// <param name="options">Options to control the behavior.</param>
 144        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0145        public static JsonValue Create(short value, JsonNodeOptions? options = null) => new JsonValuePrimitive<short>(va
 146
 147        /// <summary>
 148        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 149        /// </summary>
 150        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 151        /// <param name="options">Options to control the behavior.</param>
 152        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0153        public static JsonValue? Create(short? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValue
 154
 155        /// <summary>
 156        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 157        /// </summary>
 158        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 159        /// <param name="options">Options to control the behavior.</param>
 160        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0161        public static JsonValue Create(int value, JsonNodeOptions? options = null) => new JsonValuePrimitive<int>(value,
 162
 163        /// <summary>
 164        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 165        /// </summary>
 166        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 167        /// <param name="options">Options to control the behavior.</param>
 168        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0169        public static JsonValue? Create(int? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValuePr
 170
 171        /// <summary>
 172        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 173        /// </summary>
 174        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 175        /// <param name="options">Options to control the behavior.</param>
 176        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0177        public static JsonValue Create(long value, JsonNodeOptions? options = null) => new JsonValuePrimitive<long>(valu
 178
 179        /// <summary>
 180        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 181        /// </summary>
 182        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 183        /// <param name="options">Options to control the behavior.</param>
 184        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0185        public static JsonValue? Create(long? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 186
 187        /// <summary>
 188        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 189        /// </summary>
 190        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 191        /// <param name="options">Options to control the behavior.</param>
 192        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 193        [CLSCompliantAttribute(false)]
 0194        public static JsonValue Create(sbyte value, JsonNodeOptions? options = null) => new JsonValuePrimitive<sbyte>(va
 195
 196        /// <summary>
 197        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 198        /// </summary>
 199        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 200        /// <param name="options">Options to control the behavior.</param>
 201        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 202        [CLSCompliantAttribute(false)]
 0203        public static JsonValue? Create(sbyte? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValue
 204
 205        /// <summary>
 206        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 207        /// </summary>
 208        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 209        /// <param name="options">Options to control the behavior.</param>
 210        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0211        public static JsonValue Create(float value, JsonNodeOptions? options = null) => new JsonValuePrimitive<float>(va
 212
 213        /// <summary>
 214        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 215        /// </summary>
 216        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 217        /// <param name="options">Options to control the behavior.</param>
 218        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0219        public static JsonValue? Create(float? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValue
 220
 221        /// <summary>
 222        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 223        /// </summary>
 224        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 225        /// <param name="options">Options to control the behavior.</param>
 226        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 227        [return: NotNullIfNotNull(nameof(value))]
 0228        public static JsonValue? Create(string? value, JsonNodeOptions? options = null) => value != null ? new JsonValue
 229
 230        /// <summary>
 231        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 232        /// </summary>
 233        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 234        /// <param name="options">Options to control the behavior.</param>
 235        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 236        [CLSCompliantAttribute(false)]
 0237        public static JsonValue Create(ushort value, JsonNodeOptions? options = null) => new JsonValuePrimitive<ushort>(
 238
 239        /// <summary>
 240        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 241        /// </summary>
 242        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 243        /// <param name="options">Options to control the behavior.</param>
 244        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 245        [CLSCompliantAttribute(false)]
 0246        public static JsonValue? Create(ushort? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValu
 247
 248        /// <summary>
 249        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 250        /// </summary>
 251        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 252        /// <param name="options">Options to control the behavior.</param>
 253        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 254        [CLSCompliantAttribute(false)]
 0255        public static JsonValue Create(uint value, JsonNodeOptions? options = null) => new JsonValuePrimitive<uint>(valu
 256
 257        /// <summary>
 258        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 259        /// </summary>
 260        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 261        /// <param name="options">Options to control the behavior.</param>
 262        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 263        [CLSCompliantAttribute(false)]
 0264        public static JsonValue? Create(uint? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValueP
 265
 266        /// <summary>
 267        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 268        /// </summary>
 269        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 270        /// <param name="options">Options to control the behavior.</param>
 271        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 272        [CLSCompliantAttribute(false)]
 0273        public static JsonValue Create(ulong value, JsonNodeOptions? options = null) => new JsonValuePrimitive<ulong>(va
 274
 275        /// <summary>
 276        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 277        /// </summary>
 278        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 279        /// <param name="options">Options to control the behavior.</param>
 280        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 281        [CLSCompliantAttribute(false)]
 0282        public static JsonValue? Create(ulong? value, JsonNodeOptions? options = null) => value.HasValue ? new JsonValue
 283
 284        /// <summary>
 285        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 286        /// </summary>
 287        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 288        /// <param name="options">Options to control the behavior.</param>
 289        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0290        public static JsonValue? Create(JsonElement value, JsonNodeOptions? options = null) => JsonValue.CreateFromEleme
 291
 292        /// <summary>
 293        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 294        /// </summary>
 295        /// <param name="value">The underlying value of the new <see cref="JsonValue"/> instance.</param>
 296        /// <param name="options">Options to control the behavior.</param>
 297        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 0298        public static JsonValue? Create(JsonElement? value, JsonNodeOptions? options = null) => value is JsonElement ele
 299    }
 300}

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Nodes\JsonValue.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;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Text.Json.Serialization;
 7using System.Text.Json.Serialization.Metadata;
 8
 9namespace System.Text.Json.Nodes
 10{
 11    /// <summary>
 12    /// Represents a mutable JSON value.
 13    /// </summary>
 14    public abstract partial class JsonValue : JsonNode
 15    {
 16        internal const string CreateUnreferencedCodeMessage = "Creating JsonValue instances with non-primitive types is 
 17        internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types requires
 18
 182419        private protected JsonValue(JsonNodeOptions? options) : base(options) { }
 20
 21        /// <summary>
 22        ///   Tries to obtain the current JSON value and returns a value that indicates whether the operation succeeded.
 23        /// </summary>
 24        /// <remarks>
 25        ///   {T} can be the type or base type of the underlying value.
 26        ///   If the underlying value is a <see cref="JsonElement"/> then {T} can also be the type of any primitive
 27        ///   value supported by current <see cref="JsonElement"/>.
 28        ///   Specifying the <see cref="object"/> type for {T} will always succeed and return the underlying value as <s
 29        ///   The underlying value of a <see cref="JsonValue"/> after deserialization is an instance of <see cref="JsonE
 30        ///   otherwise it's the value specified when the <see cref="JsonValue"/> was created.
 31        /// </remarks>
 32        /// <seealso cref="JsonNode.GetValue{T}"></seealso>
 33        /// <typeparam name="T">The type of value to obtain.</typeparam>
 34        /// <param name="value">When this method returns, contains the parsed value.</param>
 35        /// <returns><see langword="true"/> if the value can be successfully obtained; otherwise, <see langword="false"/
 36        public abstract bool TryGetValue<T>([NotNullWhen(true)] out T? value);
 37
 38        /// <summary>
 39        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 40        /// </summary>
 41        /// <returns>
 42        ///   The new instance of the <see cref="JsonValue"/> class that contains the specified value.
 43        /// </returns>
 44        /// <typeparam name="T">The type of value to create.</typeparam>
 45        /// <param name="value">The value to create.</param>
 46        /// <param name="options">Options to control the behavior.</param>
 47        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 48        [RequiresUnreferencedCode(CreateUnreferencedCodeMessage + " Use the overload that takes a JsonTypeInfo, or make 
 49        [RequiresDynamicCode(CreateDynamicCodeMessage)]
 50        public static JsonValue? Create<T>(T? value, JsonNodeOptions? options = null)
 051        {
 052            if (value is null)
 053            {
 054                return null;
 55            }
 56
 057            if (value is JsonNode)
 058            {
 059                ThrowHelper.ThrowArgumentException_NodeValueNotAllowed(nameof(value));
 60            }
 61
 062            if (value is JsonElement element)
 063            {
 064                return CreateFromElement(ref element, options);
 65            }
 66
 067            var jsonTypeInfo = JsonSerializerOptions.Default.GetTypeInfo<T>();
 068            return CreateFromTypeInfo(value, jsonTypeInfo, options);
 069        }
 70
 71        /// <summary>
 72        ///   Initializes a new instance of the <see cref="JsonValue"/> class that contains the specified value.
 73        /// </summary>
 74        /// <returns>
 75        ///   The new instance of the <see cref="JsonValue"/> class that contains the specified value.
 76        /// </returns>
 77        /// <typeparam name="T">The type of value to create.</typeparam>
 78        /// <param name="value">The value to create.</param>
 79        /// <param name="jsonTypeInfo">The <see cref="JsonTypeInfo"/> that will be used to serialize the value.</param>
 80        /// <param name="options">Options to control the behavior.</param>
 81        /// <returns>The new instance of the <see cref="JsonValue"/> class that contains the specified value.</returns>
 82        public static JsonValue? Create<T>(T? value, JsonTypeInfo<T> jsonTypeInfo, JsonNodeOptions? options = null)
 083        {
 084            ArgumentNullException.ThrowIfNull(jsonTypeInfo);
 85
 086            if (value is null)
 087            {
 088                return null;
 89            }
 90
 091            if (value is JsonNode)
 092            {
 093                ThrowHelper.ThrowArgumentException_NodeValueNotAllowed(nameof(value));
 94            }
 95
 096            jsonTypeInfo.EnsureConfigured();
 97
 098            if (value is JsonElement element && jsonTypeInfo.EffectiveConverter.IsInternalConverter)
 099            {
 0100                return CreateFromElement(ref element, options);
 101            }
 102
 0103            return CreateFromTypeInfo(value, jsonTypeInfo, options);
 0104        }
 105
 106        internal override bool DeepEqualsCore(JsonNode otherNode)
 14107        {
 14108            if (GetValueKind() != otherNode.GetValueKind())
 0109            {
 0110                return false;
 111            }
 112
 113            // Fall back to slow path that converts the nodes to JsonElement.
 14114            JsonElement thisElement = ToJsonElement(this, out JsonDocument? thisDocument);
 14115            JsonElement otherElement = ToJsonElement(otherNode, out JsonDocument? otherDocument);
 116            try
 14117            {
 14118                return JsonElement.DeepEquals(thisElement, otherElement);
 119            }
 120            finally
 14121            {
 14122                thisDocument?.Dispose();
 14123                otherDocument?.Dispose();
 14124            }
 125
 126            static JsonElement ToJsonElement(JsonNode node, out JsonDocument? backingDocument)
 28127            {
 28128                if (node.UnderlyingElement is { } element)
 0129                {
 0130                    backingDocument = null;
 0131                    return element;
 132                }
 133
 28134                Utf8JsonWriter writer = Utf8JsonWriterCache.RentWriterAndBuffer(
 28135                    options: default,
 28136                    JsonSerializerOptions.BufferSizeDefault,
 28137                    out PooledByteBufferWriter output);
 138
 139                try
 28140                {
 28141                    node.WriteTo(writer);
 28142                    writer.Flush();
 28143                    Utf8JsonReader reader = new(output.WrittenSpan);
 28144                    backingDocument = JsonDocument.ParseValue(ref reader);
 28145                    return backingDocument.RootElement;
 146                }
 147                finally
 28148                {
 28149                    Utf8JsonWriterCache.ReturnWriterAndBuffer(writer, output);
 28150                }
 28151            }
 14152        }
 153
 154        internal sealed override void GetPath(ref ValueStringBuilder path, JsonNode? child)
 0155        {
 0156            Debug.Assert(child == null);
 157
 0158            Parent?.GetPath(ref path, this);
 0159        }
 160
 161        internal static JsonValue CreateFromTypeInfo<T>(T value, JsonTypeInfo<T> jsonTypeInfo, JsonNodeOptions? options 
 0162        {
 0163            Debug.Assert(jsonTypeInfo.IsConfigured);
 0164            Debug.Assert(value != null);
 165
 0166            if (JsonValue<T>.TypeIsSupportedPrimitive &&
 0167                jsonTypeInfo is { EffectiveConverter.IsInternalConverter: true } &&
 0168                (jsonTypeInfo.EffectiveNumberHandling & JsonNumberHandling.WriteAsString) is 0)
 0169            {
 170                // If the type is using the built-in converter for a known primitive,
 171                // switch to the more efficient JsonValuePrimitive<T> implementation.
 0172                return new JsonValuePrimitive<T>(value, jsonTypeInfo.EffectiveConverter, options);
 173            }
 174
 0175            return new JsonValueCustomized<T>(value, jsonTypeInfo, options);
 0176        }
 177
 178        internal static JsonValue? CreateFromElement(ref readonly JsonElement element, JsonNodeOptions? options = null)
 22179        {
 22180            switch (element.ValueKind)
 181            {
 182                case JsonValueKind.Null:
 0183                    return null;
 184
 185                case JsonValueKind.Object or JsonValueKind.Array:
 186                    // Force usage of JsonArray and JsonObject instead of supporting those in an JsonValue.
 22187                    ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray();
 188                    return null;
 189
 190                default:
 0191                    return new JsonValueOfElement(element, options);
 192            }
 0193        }
 194    }
 195}

Methods/Properties

Create(System.Boolean,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Boolean>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Byte,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Byte>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Char,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Char>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.DateTime,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.DateTime>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.DateTimeOffset,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.DateTimeOffset>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Decimal,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Decimal>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Double,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Double>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Guid,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Guid>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Int16,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Int16>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Int32,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Int32>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Int64,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Int64>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.SByte,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.SByte>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Single,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Single>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.String,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.UInt16,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.UInt16>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.UInt32,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.UInt32>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.UInt64,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.UInt64>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Text.Json.JsonElement,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(System.Nullable`1<System.Text.Json.JsonElement>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
.ctor(System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(T,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
Create(T,System.Text.Json.Serialization.Metadata.JsonTypeInfo`1<T>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
DeepEqualsCore(System.Text.Json.Nodes.JsonNode)
ToJsonElement(System.Text.Json.Nodes.JsonNode,System.Text.Json.JsonDocument&)
GetPath(System.Text.ValueStringBuilder&,System.Text.Json.Nodes.JsonNode)
CreateFromTypeInfo(T,System.Text.Json.Serialization.Metadata.JsonTypeInfo`1<T>,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)
CreateFromElement(System.Text.Json.JsonElement&,System.Nullable`1<System.Text.Json.Nodes.JsonNodeOptions>)