< Summary

Information
Line coverage
35%
Covered lines: 14
Uncovered lines: 26
Coverable lines: 40
Total lines: 74
Line coverage: 35%
Branch coverage
38%
Covered branches: 7
Total branches: 18
Branch coverage: 38.8%
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(...)100%44100%
WriteNumberWithCustomHandling(...)0%220%
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\ByteConverter.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 ByteConverter : JsonPrimitiveConverter<byte>
 11    {
 112        public ByteConverter()
 113        {
 114            IsInternalConverterForNumberType = true;
 115        }
 16
 17        public override byte Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 18418        {
 18419            if (options?.NumberHandling is not null and not JsonNumberHandling.Strict)
 020            {
 021                return ReadNumberWithCustomHandling(ref reader, options.NumberHandling, options);
 22            }
 23
 18424            return reader.GetByte();
 1625        }
 26
 27        public override void Write(Utf8JsonWriter writer, byte 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 byte ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptio
 039        {
 040            Debug.Assert(reader.TokenType == JsonTokenType.PropertyName);
 041            return reader.GetByteWithQuotes();
 042        }
 43
 44        internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, byte value, JsonSerializerOptions options,
 045        {
 046            writer.WritePropertyName(value);
 047        }
 48
 49        internal override byte ReadNumberWithCustomHandling(ref Utf8JsonReader reader, JsonNumberHandling handling, Json
 50450        {
 50451            if (reader.TokenType == JsonTokenType.String && (JsonNumberHandling.AllowReadingFromString & handling) != 0)
 15052            {
 15053                return reader.GetByteWithQuotes();
 54            }
 55
 35456            return reader.GetByte();
 4857        }
 58
 59        internal override void WriteNumberWithCustomHandling(Utf8JsonWriter writer, byte value, JsonNumberHandling handl
 060        {
 061            if ((JsonNumberHandling.WriteAsString & handling) != 0)
 062            {
 063                writer.WriteNumberValueAsString(value);
 064            }
 65            else
 066            {
 067                writer.WriteNumberValue(value);
 068            }
 069        }
 70
 71        internal override JsonSchema? GetSchema(JsonNumberHandling numberHandling) =>
 072            GetSchemaForNumericType(JsonSchemaType.Integer, numberHandling);
 73    }
 74}