< Summary

Information
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 52
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%220%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Attributes\JsonObjectCreationHandlingAttribute.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.Text.Json.Serialization.Metadata;
 6
 7namespace System.Text.Json.Serialization;
 8
 9/// <summary>
 10/// Determines how deserialization will handle object creation for fields or properties.
 11/// </summary>
 12/// <remarks>
 13/// When placed on a field or property, indicates if member will replaced or populated.
 14/// When default resolvers are used this will be mapped to <see cref="JsonPropertyInfo.ObjectCreationHandling"/>.
 15///
 16/// When placed on a type with <see cref="JsonObjectCreationHandling.Populate"/> indicates that all members
 17/// that support population will be populated. When default resolvers are used this will be mapped to <see cref="JsonTyp
 18///
 19/// Note that the attribute corresponds only to the preferred values of creation handling for properties when placed on 
 20/// For example when <see cref="JsonObjectCreationHandlingAttribute"/> with <see cref="JsonObjectCreationHandling.Popula
 21/// and property is not capable of being populated, it will be replaced.
 22/// That may be true if i.e. value type doesn't have a setter or property is of type <see cref="IEnumerable{T}"/>.
 23///
 24/// Only the property type is taken into consideration. For example if property is of type
 25/// <see cref="IEnumerable{T}"/> has runtime value of type <see cref="List{T}"/> it will not be populated
 26/// because <see cref="IEnumerable{T}"/> is not capable of populating.
 27///
 28/// Value types require a setter to support population; in such cases
 29/// deserialization will use a copy of the property value which will get assigned back to the setter once finished.
 30/// </remarks>
 31[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct | 
 32public sealed class JsonObjectCreationHandlingAttribute : JsonAttribute
 33{
 34    /// <summary>
 35    /// Indicates what configuration should be used when deserializing members.
 36    /// </summary>
 037    public JsonObjectCreationHandling Handling { get; }
 38
 39    /// <summary>
 40    /// Initializes a new instance of <see cref="JsonObjectCreationHandlingAttribute"/>.
 41    /// </summary>
 42    /// <param name="handling">The handling to apply to the current member.</param>
 043    public JsonObjectCreationHandlingAttribute(JsonObjectCreationHandling handling)
 044    {
 045        if (!JsonSerializer.IsValidCreationHandlingValue(handling))
 046        {
 047            throw new ArgumentOutOfRangeException(nameof(handling));
 48        }
 49
 050        Handling = handling;
 051    }
 52}