#region License // Copyright (c) 2007 James Newton-King // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without // restriction, including without limitation the rights to use, // copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. #endregion using System; using System.Collections; using System.Collections.Generic; namespace Newtonsoft.Json.Tests.TestObjects { public class ModelStateDictionary : IDictionary { private readonly Dictionary _innerDictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); public ModelStateDictionary() { } public ModelStateDictionary(ModelStateDictionary dictionary) { if (dictionary == null) { throw new ArgumentNullException(nameof(dictionary)); } foreach (var entry in dictionary) { _innerDictionary.Add(entry.Key, entry.Value); } } public int Count { get { return _innerDictionary.Count; } } public bool IsReadOnly { get { return ((IDictionary)_innerDictionary).IsReadOnly; } } public ICollection Keys { get { return _innerDictionary.Keys; } } public T this[string key] { get { T value; _innerDictionary.TryGetValue(key, out value); return value; } set { _innerDictionary[key] = value; } } public ICollection Values { get { return _innerDictionary.Values; } } public void Add(KeyValuePair item) { ((IDictionary)_innerDictionary).Add(item); } public void Add(string key, T value) { _innerDictionary.Add(key, value); } public void Clear() { _innerDictionary.Clear(); } public bool Contains(KeyValuePair item) { return ((IDictionary)_innerDictionary).Contains(item); } public bool ContainsKey(string key) { return _innerDictionary.ContainsKey(key); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { ((IDictionary)_innerDictionary).CopyTo(array, arrayIndex); } public IEnumerator> GetEnumerator() { return _innerDictionary.GetEnumerator(); } public void Merge(ModelStateDictionary dictionary) { if (dictionary == null) { return; } foreach (var entry in dictionary) { this[entry.Key] = entry.Value; } } public bool Remove(KeyValuePair item) { return ((IDictionary)_innerDictionary).Remove(item); } public bool Remove(string key) { return _innerDictionary.Remove(key); } public bool TryGetValue(string key, out T value) { return _innerDictionary.TryGetValue(key, out value); } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_innerDictionary).GetEnumerator(); } } }