< Summary

Information
Line coverage
10%
Covered lines: 2
Uncovered lines: 17
Coverable lines: 19
Total lines: 43
Line coverage: 10.5%
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
Read(...)100%1166.66%
Write(...)100%110%
ReadAsPropertyNameCore(...)0%440%
WriteAsPropertyNameCore(...)100%110%
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\BooleanConverter.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.Buffers.Text;
 5using System.Diagnostics;
 6using System.Text.Json.Nodes;
 7using System.Text.Json.Schema;
 8
 9namespace System.Text.Json.Serialization.Converters
 10{
 11    internal sealed class BooleanConverter : JsonPrimitiveConverter<bool>
 12    {
 13        public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 64414        {
 64415            return reader.GetBoolean();
 016        }
 17
 18        public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
 019        {
 020            writer.WriteBooleanValue(value);
 021        }
 22
 23        internal override bool ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptio
 024        {
 025            Debug.Assert(reader.TokenType == JsonTokenType.PropertyName);
 026            ReadOnlySpan<byte> propertyName = reader.GetUnescapedSpan();
 027            if (!(Utf8Parser.TryParse(propertyName, out bool value, out int bytesConsumed)
 028                  && propertyName.Length == bytesConsumed))
 029            {
 030                ThrowHelper.ThrowFormatException(DataType.Boolean);
 31            }
 32
 033            return value;
 034        }
 35
 36        internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, bool value, JsonSerializerOptions options,
 037        {
 038            writer.WritePropertyName(value);
 039        }
 40
 041        internal override JsonSchema? GetSchema(JsonNumberHandling _) => new() { Type = JsonSchemaType.Boolean };
 42    }
 43}