< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Xml.Serialization.NameKey
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Xml/Serialization/NameTable.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 107
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
Equals(...)0%440%
GetHashCode()0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Xml/Serialization/NameTable.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;
 5using System.Collections.Generic;
 6using System.Text;
 7
 8namespace CoreWCF.Xml.Serialization
 9{
 10    using System.Xml;
 11    using System;
 12    using System.Collections;
 13    using System.Collections.Generic;
 14
 15    internal sealed class NameKey
 16    {
 17        private readonly string _ns;
 18        private readonly string _name;
 19
 020        internal NameKey(string name, string ns)
 21        {
 022            _name = name;
 023            _ns = ns;
 024        }
 25
 26        public override bool Equals(object other)
 27        {
 028            if (!(other is NameKey)) return false;
 029            NameKey key = (NameKey)other;
 030            return _name == key._name && _ns == key._ns;
 31        }
 32
 33        public override int GetHashCode()
 34        {
 035            return (_ns == null ? "<null>".GetHashCode() : _ns.GetHashCode()) ^ (_name == null ? 0 : _name.GetHashCode()
 36        }
 37    }
 38    internal interface INameScope
 39    {
 40        object this[string name, string ns] { get; set; }
 41    }
 42    internal sealed class NameTable : INameScope
 43    {
 44        private readonly Dictionary<NameKey, object> _table = new Dictionary<NameKey, object>();
 45
 46        internal void Add(XmlQualifiedName qname, object value)
 47        {
 48            Add(qname.Name, qname.Namespace, value);
 49        }
 50
 51        internal void Add(string name, string ns, object value)
 52        {
 53            NameKey key = new NameKey(name, ns);
 54            _table.Add(key, value);
 55        }
 56
 57        internal object this[XmlQualifiedName qname]
 58        {
 59            get
 60            {
 61                object obj;
 62                return _table.TryGetValue(new NameKey(qname.Name, qname.Namespace), out obj) ? obj : null;
 63            }
 64            set
 65            {
 66                _table[new NameKey(qname.Name, qname.Namespace)] = value;
 67            }
 68        }
 69        internal object this[string name, string ns]
 70        {
 71            get
 72            {
 73                object obj;
 74                return _table.TryGetValue(new NameKey(name, ns), out obj) ? obj : null;
 75            }
 76            set
 77            {
 78                _table[new NameKey(name, ns)] = value;
 79            }
 80        }
 81        object INameScope.this[string name, string ns]
 82        {
 83            get
 84            {
 85                object obj;
 86                _table.TryGetValue(new NameKey(name, ns), out obj);
 87                return obj;
 88            }
 89            set
 90            {
 91                _table[new NameKey(name, ns)] = value;
 92            }
 93        }
 94
 95        internal ICollection Values
 96        {
 97            get { return _table.Values; }
 98        }
 99
 100        internal Array ToArray(Type type)
 101        {
 102            Array a = Array.CreateInstance(type, _table.Count);
 103            ((ICollection)_table.Values).CopyTo(a, 0);
 104            return a;
 105        }
 106    }
 107}