using System; using System.Collections; using System.Collections.Generic; namespace Unity.VisualScripting { public class NonNullableDictionary : IDictionary, IDictionary { public NonNullableDictionary() { dictionary = new Dictionary(); } public NonNullableDictionary(int capacity) { dictionary = new Dictionary(capacity); } public NonNullableDictionary(IEqualityComparer comparer) { dictionary = new Dictionary(comparer); } public NonNullableDictionary(IDictionary dictionary) { this.dictionary = new Dictionary(dictionary); } public NonNullableDictionary(int capacity, IEqualityComparer comparer) { dictionary = new Dictionary(capacity, comparer); } public NonNullableDictionary(IDictionary dictionary, IEqualityComparer comparer) { this.dictionary = new Dictionary(dictionary, comparer); } private readonly Dictionary dictionary; public TValue this[TKey key] { get { return dictionary[key]; } set { dictionary[key] = value; } } object IDictionary.this[object key] { get { return ((IDictionary)dictionary)[key]; } set { ((IDictionary)dictionary)[key] = value; } } public int Count => dictionary.Count; public bool IsSynchronized => ((ICollection)dictionary).IsSynchronized; public object SyncRoot => ((ICollection)dictionary).SyncRoot; public bool IsReadOnly => false; public ICollection Keys => dictionary.Keys; ICollection IDictionary.Values => ((IDictionary)dictionary).Values; ICollection IDictionary.Keys => ((IDictionary)dictionary).Keys; public ICollection Values => dictionary.Values; public bool IsFixedSize => ((IDictionary)dictionary).IsFixedSize; public void CopyTo(Array array, int index) { ((ICollection)dictionary).CopyTo(array, index); } void ICollection>.Add(KeyValuePair item) { ((ICollection>)dictionary).Add(item); } public void Add(TKey key, TValue value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } dictionary.Add(key, value); } public void Add(object key, object value) { ((IDictionary)dictionary).Add(key, value); } public void Clear() { dictionary.Clear(); } public bool Contains(object key) { return ((IDictionary)dictionary).Contains(key); } IDictionaryEnumerator IDictionary.GetEnumerator() { return ((IDictionary)dictionary).GetEnumerator(); } public void Remove(object key) { ((IDictionary)dictionary).Remove(key); } bool ICollection>.Contains(KeyValuePair item) { return ((ICollection>)dictionary).Contains(item); } public bool ContainsKey(TKey key) { return dictionary.ContainsKey(key); } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { ((ICollection>)dictionary).CopyTo(array, arrayIndex); } public IEnumerator> GetEnumerator() { return dictionary.GetEnumerator(); } bool ICollection>.Remove(KeyValuePair item) { return ((ICollection>)dictionary).Remove(item); } public bool Remove(TKey key) { return dictionary.Remove(key); } public bool TryGetValue(TKey key, out TValue value) { return dictionary.TryGetValue(key, out value); } IEnumerator IEnumerable.GetEnumerator() { return dictionary.GetEnumerator(); } } }