< Summary

Line coverage
28%
Covered lines: 12
Uncovered lines: 30
Coverable lines: 42
Total lines: 81
Line coverage: 28.5%
Branch coverage
27%
Covered branches: 5
Total branches: 18
Branch coverage: 27.7%
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(...)50%4457.14%
WriteNumberWithCustomHandling(...)0%220%
GetSchema(...)100%110%
GetSupportedJsonValueTypes(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/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)
 818        {
 819            if (options?.NumberHandling is not null and not JsonNumberHandling.Strict)
 020            {
 021                return ReadNumberWithCustomHandling(ref reader, options.NumberHandling, options);
 22            }
 23
 824            return reader.GetUInt32();
 425        }
 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
 451        {
 452            if (reader.TokenType == JsonTokenType.String &&
 453                (JsonNumberHandling.AllowReadingFromString & handling) != 0)
 054            {
 055                return reader.GetUInt32WithQuotes();
 56            }
 57
 458            return reader.GetUInt32();
 059        }
 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        internal override JsonValueType GetSupportedJsonValueTypes(JsonNumberHandling numberHandling) =>
 078            GetSupportedJsonValueTypesForNumericType(numberHandling);
 79    }
 80}
 81