| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using Azure.Messaging.ServiceBus.Amqp; |
| | 8 | |
|
| | 9 | | namespace Azure.Messaging.ServiceBus.Primitives |
| | 10 | | { |
| | 11 | | internal sealed class PropertyDictionary : IDictionary<string, object> |
| | 12 | | { |
| | 13 | | private readonly IDictionary<string, object> _inner; |
| | 14 | |
|
| 130 | 15 | | public PropertyDictionary() |
| | 16 | | { |
| 130 | 17 | | _inner = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); |
| 130 | 18 | | } |
| | 19 | |
|
| 24 | 20 | | public PropertyDictionary(IDictionary<string, object> container) |
| | 21 | | { |
| 24 | 22 | | _inner = container; |
| 24 | 23 | | } |
| | 24 | |
|
| 0 | 25 | | public ICollection<string> Keys => _inner.Keys; |
| | 26 | |
|
| 0 | 27 | | public ICollection<object> Values => _inner.Values; |
| | 28 | |
|
| 76 | 29 | | public int Count => _inner.Count; |
| | 30 | |
|
| 0 | 31 | | public bool IsReadOnly => _inner.IsReadOnly; |
| | 32 | |
|
| | 33 | | public object this[string key] |
| | 34 | | { |
| 0 | 35 | | get => _inner[key]; |
| | 36 | |
|
| | 37 | | set |
| | 38 | | { |
| 0 | 39 | | if (IsSupportedObject(value)) |
| | 40 | | { |
| 0 | 41 | | _inner[key] = value; |
| | 42 | | } |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public void Add(string key, object value) |
| | 47 | | { |
| 172 | 48 | | if (IsSupportedObject(value)) |
| | 49 | | { |
| 172 | 50 | | _inner.Add(key, value); |
| | 51 | | } |
| 172 | 52 | | } |
| | 53 | |
|
| | 54 | | public bool ContainsKey(string key) |
| | 55 | | { |
| 0 | 56 | | return _inner.ContainsKey(key); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public bool Remove(string key) |
| | 60 | | { |
| 0 | 61 | | return _inner.Remove(key); |
| | 62 | | } |
| | 63 | |
|
| | 64 | | public bool TryGetValue(string key, out object value) |
| | 65 | | { |
| 88 | 66 | | return _inner.TryGetValue(key, out value); |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public void Add(KeyValuePair<string, object> item) |
| | 70 | | { |
| 0 | 71 | | _inner.Add(item); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public void Clear() |
| | 75 | | { |
| 0 | 76 | | _inner.Clear(); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public bool Contains(KeyValuePair<string, object> item) |
| | 80 | | { |
| 0 | 81 | | return _inner.Contains(item); |
| | 82 | | } |
| | 83 | |
|
| | 84 | | public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex) |
| | 85 | | { |
| 0 | 86 | | _inner.CopyTo(array, arrayIndex); |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | public bool Remove(KeyValuePair<string, object> item) |
| | 90 | | { |
| 0 | 91 | | return _inner.Remove(item); |
| | 92 | | } |
| | 93 | |
|
| | 94 | | public IEnumerator<KeyValuePair<string, object>> GetEnumerator() |
| | 95 | | { |
| 88 | 96 | | return _inner.GetEnumerator(); |
| | 97 | | } |
| | 98 | |
|
| | 99 | | IEnumerator IEnumerable.GetEnumerator() |
| | 100 | | { |
| 0 | 101 | | return _inner.GetEnumerator(); |
| | 102 | | } |
| | 103 | |
|
| | 104 | | private static bool IsSupportedObject(object value) |
| | 105 | | { |
| 172 | 106 | | if (value != null) |
| | 107 | | { |
| 172 | 108 | | var type = value.GetType(); |
| | 109 | |
|
| 172 | 110 | | if (!SerializationUtilities.IsSupportedPropertyType(type)) |
| | 111 | | { |
| 0 | 112 | | throw new ArgumentException(Resources.NotSupportedPropertyType.FormatForUser(type), nameof(value)); |
| | 113 | | } |
| | 114 | | } |
| | 115 | |
|
| 172 | 116 | | return true; |
| | 117 | | } |
| | 118 | |
|
| | 119 | | internal PropertyDictionary Clone() => |
| 24 | 120 | | new PropertyDictionary(_inner); |
| | 121 | | } |
| | 122 | | } |