< Summary

Information
Line coverage
36%
Covered lines: 15
Uncovered lines: 26
Coverable lines: 41
Total lines: 77
Line coverage: 36.5%
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\UInt32Converter.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 UInt32Converter : JsonPrimitiveConverter<uint>
 11    {
 112        public UInt32Converter()
 113        {
 114            IsInternalConverterForNumberType = true;
 115        }
 16
 17        public override uint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 17418        {
 17419            if (options?.NumberHandling is not null and not JsonNumberHandling.Strict)
 020            {
 021                return ReadNumberWithCustomHandling(ref reader, options.NumberHandling, options);
 22            }
 23
 17424            return reader.GetUInt32();
 2225        }
 26
 27        public override void Write(Utf8JsonWriter writer, uint 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
 35            // For performance, lift up the writer implementation.
 036            writer.WriteNumberValue((ulong)value);
 037        }
 38
 39        internal override uint ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptio
 040        {
 041            Debug.Assert(reader.TokenType == JsonTokenType.PropertyName);
 042            return reader.GetUInt32WithQuotes();
 043        }
 44
 45        internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, uint value, JsonSerializerOptions options,
 046        {
 047            writer.WritePropertyName(value);
 048        }
 49
 50        internal override uint ReadNumberWithCustomHandling(ref Utf8JsonReader reader, JsonNumberHandling handling, Json
 46051        {
 46052            if (reader.TokenType == JsonTokenType.String &&
 46053                (JsonNumberHandling.AllowReadingFromString & handling) != 0)
 14054            {
 14055                return reader.GetUInt32WithQuotes();
 56            }
 57
 32058            return reader.GetUInt32();
 6259        }
 60
 61        internal override void WriteNumberWithCustomHandling(Utf8JsonWriter writer, uint value, JsonNumberHandling handl
 062        {
 063            if ((JsonNumberHandling.WriteAsString & handling) != 0)
 064            {
 065                writer.WriteNumberValueAsString(value);
 066            }
 67            else
 068            {
 69                // For performance, lift up the writer implementation.
 070                writer.WriteNumberValue((ulong)value);
 071            }
 072        }
 73
 74        internal override JsonSchema? GetSchema(JsonNumberHandling numberHandling) =>
 075            GetSchemaForNumericType(JsonSchemaType.Integer, numberHandling);
 76    }
 77}