< Summary

Information
Class: System.Net.Http.Headers.Int64NumberHeaderParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\Int64NumberHeaderParser.cs
Line coverage
90%
Covered lines: 18
Uncovered lines: 2
Coverable lines: 20
Total lines: 53
Line coverage: 90%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
ToString(...)100%11100%
GetParsedValueLength(...)83.33%6683.33%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\Int64NumberHeaderParser.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.Globalization;
 6
 7namespace System.Net.Http.Headers
 8{
 9    internal sealed class Int64NumberHeaderParser : BaseHeaderParser
 10    {
 11        // Note that we don't need a custom comparer even though we have a value type that gets boxed (comparing two
 12        // equal boxed value types returns 'false' since the object instances used for boxing the two values are
 13        // different). The reason is that the comparer is only used by HttpHeaders when comparing values in a collection
 14        // Value types are never used in collections (in fact HttpHeaderValueCollection expects T to be a reference
 15        // type).
 16
 117        internal static readonly Int64NumberHeaderParser Parser = new Int64NumberHeaderParser();
 18
 19        private Int64NumberHeaderParser()
 120            : base(false)
 121        {
 122        }
 23
 24        public override string ToString(object value)
 5725        {
 5726            Debug.Assert(value is long);
 27
 5728            return ((long)value).ToString(NumberFormatInfo.InvariantInfo);
 5729        }
 30
 31        protected override int GetParsedValueLength(string value, int startIndex, object? storeValue,
 32            out object? parsedValue)
 8633        {
 8634            parsedValue = null;
 35
 8636            int numberLength = HttpRuleParser.GetNumberLength(value, startIndex, false);
 37
 8638            if ((numberLength == 0) || (numberLength > HttpRuleParser.MaxInt64Digits))
 1439            {
 1440                return 0;
 41            }
 42
 43            long result;
 7244            if (!HeaderUtilities.TryParseInt64(value, startIndex, numberLength, out result))
 045            {
 046                return 0;
 47            }
 48
 7249            parsedValue = result;
 7250            return numberLength;
 8651        }
 52    }
 53}