| | | 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 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Text; |
| | | 7 | | |
| | | 8 | | namespace 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 | | { |
| | 0 | 44 | | private readonly Dictionary<NameKey, object> _table = new Dictionary<NameKey, object>(); |
| | | 45 | | |
| | | 46 | | internal void Add(XmlQualifiedName qname, object value) |
| | | 47 | | { |
| | 0 | 48 | | Add(qname.Name, qname.Namespace, value); |
| | 0 | 49 | | } |
| | | 50 | | |
| | | 51 | | internal void Add(string name, string ns, object value) |
| | | 52 | | { |
| | 0 | 53 | | NameKey key = new NameKey(name, ns); |
| | 0 | 54 | | _table.Add(key, value); |
| | 0 | 55 | | } |
| | | 56 | | |
| | | 57 | | internal object this[XmlQualifiedName qname] |
| | | 58 | | { |
| | | 59 | | get |
| | | 60 | | { |
| | | 61 | | object obj; |
| | 0 | 62 | | return _table.TryGetValue(new NameKey(qname.Name, qname.Namespace), out obj) ? obj : null; |
| | | 63 | | } |
| | | 64 | | set |
| | | 65 | | { |
| | 0 | 66 | | _table[new NameKey(qname.Name, qname.Namespace)] = value; |
| | 0 | 67 | | } |
| | | 68 | | } |
| | | 69 | | internal object this[string name, string ns] |
| | | 70 | | { |
| | | 71 | | get |
| | | 72 | | { |
| | | 73 | | object obj; |
| | 0 | 74 | | return _table.TryGetValue(new NameKey(name, ns), out obj) ? obj : null; |
| | | 75 | | } |
| | | 76 | | set |
| | | 77 | | { |
| | 0 | 78 | | _table[new NameKey(name, ns)] = value; |
| | 0 | 79 | | } |
| | | 80 | | } |
| | | 81 | | object INameScope.this[string name, string ns] |
| | | 82 | | { |
| | | 83 | | get |
| | | 84 | | { |
| | | 85 | | object obj; |
| | 0 | 86 | | _table.TryGetValue(new NameKey(name, ns), out obj); |
| | 0 | 87 | | return obj; |
| | | 88 | | } |
| | | 89 | | set |
| | | 90 | | { |
| | 0 | 91 | | _table[new NameKey(name, ns)] = value; |
| | 0 | 92 | | } |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | internal ICollection Values |
| | | 96 | | { |
| | 0 | 97 | | get { return _table.Values; } |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | internal Array ToArray(Type type) |
| | | 101 | | { |
| | 0 | 102 | | Array a = Array.CreateInstance(type, _table.Count); |
| | 0 | 103 | | ((ICollection)_table.Values).CopyTo(a, 0); |
| | 0 | 104 | | return a; |
| | | 105 | | } |
| | | 106 | | } |
| | | 107 | | } |