Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UDictionary.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Diagnostics;
5using System.Runtime.InteropServices;
6using System.Runtime.Serialization;
7using UnityEngine;
8
9[Serializable]
10[ComVisible(false)]
11[DebuggerDisplay("Count = {Count}")]
12public class UDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDictionary, ICollection, ISerializable, IDeserializationCallback, ISerializationCallbackReceiver
13{
14 [SerializeField]
15 private List<TKey> keys = new List<TKey>();
16
17 [SerializeField]
18 private List<TValue> values = new List<TValue>();
19
20 [NonSerialized]
21 private Dictionary<TKey, TValue> dictionary;
22
23 public bool IsFixedSize => false;
24
25 public ICollection<TKey> Keys => dictionary.Keys;
26
27 ICollection IDictionary.Keys => dictionary.Keys;
28
29 public ICollection<TValue> Values => dictionary.Values;
30
31 ICollection IDictionary.Values => dictionary.Values;
32
33 public TValue this[TKey key]
34 {
35 get
36 {
37 return dictionary[key];
38 }
39 set
40 {
41 dictionary[key] = value;
42 }
43 }
44
45 object IDictionary.this[object key]
46 {
47 get
48 {
49 if (!(key is TKey))
50 {
51 return null;
52 }
53 return dictionary[(TKey)key];
54 }
55 set
56 {
57 if (key is TKey && (value is TValue || value == null))
58 {
59 dictionary[(TKey)key] = (TValue)value;
60 }
61 }
62 }
63
64 public int Count => dictionary.Count;
65
66 public bool IsReadOnly => false;
67
68 public bool IsSynchronized => false;
69
70 public object SyncRoot => null;
71
72 public UDictionary()
73 {
74 dictionary = new Dictionary<TKey, TValue>();
75 }
76
77 public UDictionary(IEqualityComparer<TKey> comparer)
78 {
79 dictionary = new Dictionary<TKey, TValue>(comparer);
80 }
81
82 public UDictionary(IDictionary<TKey, TValue> dictionary)
83 {
84 this.dictionary = new Dictionary<TKey, TValue>(dictionary);
85 }
86
87 public UDictionary(int capacity)
88 {
89 dictionary = new Dictionary<TKey, TValue>(capacity);
90 }
91
92 public UDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer)
93 {
94 this.dictionary = new Dictionary<TKey, TValue>(dictionary, comparer);
95 }
96
97 public UDictionary(int capacity, IEqualityComparer<TKey> comparer)
98 {
99 dictionary = new Dictionary<TKey, TValue>(capacity, comparer);
100 }
101
102 public void OnAfterDeserialize()
103 {
104 dictionary.Clear();
105 for (int i = 0; i < keys.Count; i++)
106 {
107 if (keys[i] != null && (!(keys[i] is UnityEngine.Object) || (bool)(UnityEngine.Object)(object)keys[i]))
108 {
109 dictionary.Add(keys[i], values[i]);
110 }
111 }
112 }
113
114 public void OnBeforeSerialize()
115 {
116 keys.Clear();
117 values.Clear();
118 foreach (KeyValuePair<TKey, TValue> item in dictionary)
119 {
120 if (item.Key != null && (!(item.Key is UnityEngine.Object) || (bool)(UnityEngine.Object)(object)item.Key))
121 {
122 keys.Add(item.Key);
123 values.Add(item.Value);
124 }
125 }
126 }
127
128 public void GetObjectData(SerializationInfo info, StreamingContext context)
129 {
130 dictionary.GetObjectData(info, context);
131 }
132
133 public void OnDeserialization(object sender)
134 {
135 dictionary.OnDeserialization(sender);
136 }
137
138 public void Add(TKey key, TValue value)
139 {
140 dictionary.Add(key, value);
141 }
142
143 void IDictionary.Add(object key, object value)
144 {
145 if (key is TKey && (value is TValue || value == null))
146 {
147 dictionary.Add((TKey)key, (TValue)value);
148 }
149 }
150
151 public bool ContainsKey(TKey key)
152 {
153 return dictionary.ContainsKey(key);
154 }
155
156 bool IDictionary.Contains(object key)
157 {
158 if (!(key is TKey))
159 {
160 return false;
161 }
162 return dictionary.ContainsKey((TKey)key);
163 }
164
165 public bool Remove(TKey key)
166 {
167 return dictionary.Remove(key);
168 }
169
170 void IDictionary.Remove(object key)
171 {
172 if (key is TKey)
173 {
174 dictionary.Remove((TKey)key);
175 }
176 }
177
178 public bool TryGetValue(TKey key, out TValue value)
179 {
180 return dictionary.TryGetValue(key, out value);
181 }
182
183 IDictionaryEnumerator IDictionary.GetEnumerator()
184 {
185 return ((IDictionary)dictionary).GetEnumerator();
186 }
187
188 public void Add(KeyValuePair<TKey, TValue> item)
189 {
190 dictionary.Add(item.Key, item.Value);
191 }
192
193 public void Clear()
194 {
195 dictionary.Clear();
196 }
197
198 public bool Contains(KeyValuePair<TKey, TValue> item)
199 {
200 if (dictionary.ContainsKey(item.Key))
201 {
202 return dictionary[item.Key].Equals(item.Value);
203 }
204 return false;
205 }
206
207 void ICollection.CopyTo(Array array, int index)
208 {
209 }
210
211 void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
212 {
213 }
214
215 public bool Remove(KeyValuePair<TKey, TValue> item)
216 {
217 return dictionary.Remove(item.Key);
218 }
219
220 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
221 {
222 return dictionary.GetEnumerator();
223 }
224
225 IEnumerator IEnumerable.GetEnumerator()
226 {
227 return dictionary.GetEnumerator();
228 }
229}
object SyncRoot
Definition: UDictionary.cs:70
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()
Definition: UDictionary.cs:220
List< TValue > values
Definition: UDictionary.cs:18
void GetObjectData(SerializationInfo info, StreamingContext context)
Definition: UDictionary.cs:128
Dictionary< TKey, TValue > dictionary
Definition: UDictionary.cs:21
bool IsFixedSize
Definition: UDictionary.cs:23
ICollection< TKey > Keys
Definition: UDictionary.cs:25
bool ContainsKey(TKey key)
Definition: UDictionary.cs:151
UDictionary(int capacity, IEqualityComparer< TKey > comparer)
Definition: UDictionary.cs:97
UDictionary(int capacity)
Definition: UDictionary.cs:87
List< TKey > keys
Definition: UDictionary.cs:15
bool Contains(KeyValuePair< TKey, TValue > item)
Definition: UDictionary.cs:198
void OnAfterDeserialize()
Definition: UDictionary.cs:102
UDictionary(IDictionary< TKey, TValue > dictionary)
Definition: UDictionary.cs:82
void OnDeserialization(object sender)
Definition: UDictionary.cs:133
bool TryGetValue(TKey key, out TValue value)
Definition: UDictionary.cs:178
bool Remove(KeyValuePair< TKey, TValue > item)
Definition: UDictionary.cs:215
void Add(TKey key, TValue value)
Definition: UDictionary.cs:138
void Add(KeyValuePair< TKey, TValue > item)
Definition: UDictionary.cs:188
bool IsReadOnly
Definition: UDictionary.cs:66
bool Remove(TKey key)
Definition: UDictionary.cs:165
bool IsSynchronized
Definition: UDictionary.cs:68
UDictionary(IEqualityComparer< TKey > comparer)
Definition: UDictionary.cs:77
ICollection< TValue > Values
Definition: UDictionary.cs:29
void Clear()
Definition: UDictionary.cs:193
UDictionary(IDictionary< TKey, TValue > dictionary, IEqualityComparer< TKey > comparer)
Definition: UDictionary.cs:92
void OnBeforeSerialize()
Definition: UDictionary.cs:114