< Summary

Class:Azure.Core.Http.Multipart.StringSegmentComparer
Assembly:Azure.Storage.Blobs.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\StringSegmentComparer.cs
Covered lines:0
Uncovered lines:15
Coverable lines:15
Total lines:53
Line coverage:0% (0 of 15)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Ordinal()-0%100%
.cctor()-0%100%
get_OrdinalIgnoreCase()-0%100%
.ctor(...)-0%100%
get_Comparison()-0%100%
get_Comparer()-0%100%
Compare(...)-0%100%
Equals(...)-0%100%
GetHashCode(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\StringSegmentComparer.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// Copied from https://github.com/aspnet/Extensions/tree/master/src/Primitives/src
 5
 6using System;
 7using System.Collections.Generic;
 8
 9namespace Azure.Core.Http.Multipart
 10{
 11    internal class StringSegmentComparer : IComparer<StringSegment>, IEqualityComparer<StringSegment>
 12    {
 013        public static StringSegmentComparer Ordinal { get; }
 014            = new StringSegmentComparer(StringComparison.Ordinal, StringComparer.Ordinal);
 15
 016        public static StringSegmentComparer OrdinalIgnoreCase { get; }
 017            = new StringSegmentComparer(StringComparison.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase);
 18
 019        private StringSegmentComparer(StringComparison comparison, StringComparer comparer)
 20        {
 021            Comparison = comparison;
 022            Comparer = comparer;
 023        }
 24
 025        private StringComparison Comparison { get; }
 026        private StringComparer Comparer { get; }
 27
 28        public int Compare(StringSegment x, StringSegment y)
 29        {
 030            return StringSegment.Compare(x, y, Comparison);
 31        }
 32
 33        public bool Equals(StringSegment x, StringSegment y)
 34        {
 035            return StringSegment.Equals(x, y, Comparison);
 36        }
 37
 38        public int GetHashCode(StringSegment obj)
 39        {
 40#if NETCOREAPP
 41            return string.GetHashCode(obj.AsSpan(), Comparison);
 42#else
 043            if (!obj.HasValue)
 44            {
 045                return 0;
 46            }
 47
 48            // .NET Core strings use randomized hash codes for security reasons. Consequently we must materialize the St
 049            return Comparer.GetHashCode(obj.Value);
 50#endif
 51        }
 52    }
 53}