< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 25
Coverable lines: 25
Total lines: 99
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetReaderOptions()100%110%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Document\JsonDocumentOptions.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;
 5
 6namespace System.Text.Json
 7{
 8    /// <summary>
 9    /// Provides the ability for the user to define custom behavior when parsing JSON to create a <see cref="JsonDocumen
 10    /// </summary>
 11    public struct JsonDocumentOptions
 12    {
 13        internal const int DefaultMaxDepth = 64;
 14
 15        private int _maxDepth;
 16        private JsonCommentHandling _commentHandling;
 17
 18        /// <summary>
 19        /// Defines how the <see cref="Utf8JsonReader"/> should handle comments when reading through the JSON.
 20        /// </summary>
 21        /// <exception cref="ArgumentOutOfRangeException">
 22        /// Thrown when the comment handling enum is set to a value that is not supported (or not within the <see cref="
 23        /// </exception>
 24        /// <remarks>
 25        /// By default <exception cref="JsonException"/> is thrown if a comment is encountered.
 26        /// </remarks>
 27        public JsonCommentHandling CommentHandling
 28        {
 029            readonly get => _commentHandling;
 30            set
 031            {
 032                Debug.Assert(value >= 0);
 033                if (value > JsonCommentHandling.Skip)
 034                    throw new ArgumentOutOfRangeException(nameof(value), SR.JsonDocumentDoesNotSupportComments);
 35
 036                _commentHandling = value;
 037            }
 38        }
 39
 40        /// <summary>
 41        /// Gets or sets the maximum depth allowed when reading JSON, with the default (i.e. 0) indicating a max depth o
 42        /// </summary>
 43        /// <exception cref="ArgumentOutOfRangeException">
 44        /// Thrown when the max depth is set to a negative value.
 45        /// </exception>
 46        /// <remarks>
 47        /// Reading past this depth will throw a <exception cref="JsonException"/>.
 48        /// </remarks>
 49        public int MaxDepth
 50        {
 051            readonly get => _maxDepth;
 52            set
 053            {
 054                if (value < 0)
 055                {
 056                    ThrowHelper.ThrowArgumentOutOfRangeException_MaxDepthMustBePositive(nameof(value));
 57                }
 58
 059                _maxDepth = value;
 060            }
 61        }
 62
 63        /// <summary>
 64        /// Defines whether an extra comma at the end of a list of JSON values in an object or array
 65        /// is allowed (and ignored) within the JSON payload being read.
 66        /// </summary>
 67        /// <remarks>
 68        /// By default, it's set to false, and <exception cref="JsonException"/> is thrown if a trailing comma is encoun
 69        /// </remarks>
 070        public bool AllowTrailingCommas { get; set; }
 71
 72        /// <summary>
 73        /// Defines whether duplicate property names are allowed when deserializing JSON objects.
 74        /// </summary>
 75        /// <remarks>
 76        /// <para>
 77        /// By default, it's set to true. If set to false, <see cref="JsonException"/> is thrown
 78        /// when a duplicate property name is encountered during deserialization.
 79        /// </para>
 80        /// </remarks>
 81        public bool AllowDuplicateProperties
 82        {
 83            // These are negated because the declaring type is a struct and we want the value to be true
 84            // for the default struct value.
 085            get => !field;
 086            set => field = !value;
 87        }
 88
 89        internal JsonReaderOptions GetReaderOptions()
 090        {
 091            return new JsonReaderOptions
 092            {
 093                AllowTrailingCommas = AllowTrailingCommas,
 094                CommentHandling = CommentHandling,
 095                MaxDepth = MaxDepth
 096            };
 097        }
 98    }
 99}