< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Xml.Serialization.NameTable
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: 20
Coverable lines: 20
Total lines: 107
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
Add(...)100%110%
Add(...)100%110%
ToArray(...)100%110%

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
 20        internal NameKey(string name, string ns)
 21        {
 22            _name = name;
 23            _ns = ns;
 24        }
 25
 26        public override bool Equals(object other)
 27        {
 28            if (!(other is NameKey)) return false;
 29            NameKey key = (NameKey)other;
 30            return _name == key._name && _ns == key._ns;
 31        }
 32
 33        public override int GetHashCode()
 34        {
 35            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    {
 044        private readonly Dictionary<NameKey, object> _table = new Dictionary<NameKey, object>();
 45
 46        internal void Add(XmlQualifiedName qname, object value)
 47        {
 048            Add(qname.Name, qname.Namespace, value);
 049        }
 50
 51        internal void Add(string name, string ns, object value)
 52        {
 053            NameKey key = new NameKey(name, ns);
 054            _table.Add(key, value);
 055        }
 56
 57        internal object this[XmlQualifiedName qname]
 58        {
 59            get
 60            {
 61                object obj;
 062                return _table.TryGetValue(new NameKey(qname.Name, qname.Namespace), out obj) ? obj : null;
 63            }
 64            set
 65            {
 066                _table[new NameKey(qname.Name, qname.Namespace)] = value;
 067            }
 68        }
 69        internal object this[string name, string ns]
 70        {
 71            get
 72            {
 73                object obj;
 074                return _table.TryGetValue(new NameKey(name, ns), out obj) ? obj : null;
 75            }
 76            set
 77            {
 078                _table[new NameKey(name, ns)] = value;
 079            }
 80        }
 81        object INameScope.this[string name, string ns]
 82        {
 83            get
 84            {
 85                object obj;
 086                _table.TryGetValue(new NameKey(name, ns), out obj);
 087                return obj;
 88            }
 89            set
 90            {
 091                _table[new NameKey(name, ns)] = value;
 092            }
 93        }
 94
 95        internal ICollection Values
 96        {
 097            get { return _table.Values; }
 98        }
 99
 100        internal Array ToArray(Type type)
 101        {
 0102            Array a = Array.CreateInstance(type, _table.Count);
 0103            ((ICollection)_table.Values).CopyTo(a, 0);
 0104            return a;
 105        }
 106    }
 107}