< Summary

Information
Line coverage
36%
Covered lines: 18
Uncovered lines: 32
Coverable lines: 50
Total lines: 85
Line coverage: 36%
Branch coverage
36%
Covered branches: 8
Total branches: 22
Branch coverage: 36.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
Read(...)50%6666.66%
Write(...)0%660%
ReadAsPropertyNameCore(...)100%110%
WriteAsPropertyNameCore(...)100%110%
ReadNumberWithCustomHandling(...)83.33%6683.33%
WriteNumberWithCustomHandling(...)0%440%
GetSchema(...)100%110%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Converters\Value\DoubleConverter.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.Text.Json.Nodes;
 6using System.Text.Json.Schema;
 7
 8namespace System.Text.Json.Serialization.Converters
 9{
 10    internal sealed class DoubleConverter : JsonPrimitiveConverter<double>
 11    {
 112        public DoubleConverter()
 113        {
 114            IsInternalConverterForNumberType = true;
 115        }
 16
 17        public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 19218        {
 19219            if (options?.NumberHandling is not null and not JsonNumberHandling.Strict)
 020            {
 021                return ReadNumberWithCustomHandling(ref reader, options.NumberHandling, options);
 22            }
 23
 19224            return reader.GetDouble();
 3025        }
 26
 27        public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
 028        {
 029            if (options?.NumberHandling is not null and not JsonNumberHandling.Strict)
 030            {
 031                WriteNumberWithCustomHandling(writer, value, options.NumberHandling);
 032                return;
 33            }
 34
 035            writer.WriteNumberValue(value);
 036        }
 37
 38        internal override double ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOpt
 039        {
 040            Debug.Assert(reader.TokenType == JsonTokenType.PropertyName);
 041            return reader.GetDoubleWithQuotes();
 042        }
 43
 44        internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, double value, JsonSerializerOptions option
 045        {
 046            writer.WritePropertyName(value);
 047        }
 48
 49        internal override double ReadNumberWithCustomHandling(ref Utf8JsonReader reader, JsonNumberHandling handling, Js
 49050        {
 49051            if (reader.TokenType == JsonTokenType.String)
 19652            {
 19653                if ((JsonNumberHandling.AllowReadingFromString & handling) != 0)
 16054                {
 16055                    return reader.GetDoubleWithQuotes();
 56                }
 3657                else if ((JsonNumberHandling.AllowNamedFloatingPointLiterals & handling) != 0)
 058                {
 059                    return reader.GetDoubleFloatingPointConstant();
 60                }
 3661            }
 62
 33063            return reader.GetDouble();
 11864        }
 65
 66        internal override void WriteNumberWithCustomHandling(Utf8JsonWriter writer, double value, JsonNumberHandling han
 067        {
 068            if ((JsonNumberHandling.WriteAsString & handling) != 0)
 069            {
 070                writer.WriteNumberValueAsString(value);
 071            }
 072            else if ((JsonNumberHandling.AllowNamedFloatingPointLiterals & handling) != 0)
 073            {
 074                writer.WriteFloatingPointConstant(value);
 075            }
 76            else
 077            {
 078                writer.WriteNumberValue(value);
 079            }
 080        }
 81
 82        internal override JsonSchema? GetSchema(JsonNumberHandling numberHandling) =>
 083                GetSchemaForNumericType(JsonSchemaType.Number, numberHandling, isIeeeFloatingPoint: true);
 84    }
 85}