|
| | Context () |
| | Context (ref ConcurrentDictionary< Enum, object > contextDictionary) |
| | Context (ref ConcurrentDictionary< Enum, object > contextDictionary, ref ConcurrentDictionary< Enum, object > eventDictionary) |
| void | Set< T > (Enum key, T value) |
| T | Get< T > (Enum key) |
| bool | TryGet< T > (Enum key, out T value) |
| bool | Has (Enum key) |
| bool | Remove (Enum key) |
| void | ClearData () |
| Context | CloneContext () |
| void | MergeContexts (Context other, bool overwrite=true) |
| void | RegisterEvent (Enum key, FlexibleEvent evt) |
| void | RegisterEvent< T > (Enum key, FlexibleEvent< T > evt) |
| bool | TryGetEvent (Enum key, out FlexibleEvent evt) |
| bool | TryGetEvent< T > (Enum key, out FlexibleEvent< T > evt) |
| void | InvokeEvent (Enum key) |
| void | InvokeEvent< T > (Enum key, T value) |
| bool | HasEvent (Enum key) |
| bool | RemoveEvent (Enum key) |
| void | ClearEvents () |
| void | Dispose () |
|
| ConcurrentDictionary< Enum, object > | _data = new ConcurrentDictionary<Enum, object>() |
| ConcurrentDictionary< Enum, object > | _eventMap = new ConcurrentDictionary<Enum, object>() |
◆ Context() [1/3]
| IuvoUnity.DataStructs.Context.Context |
( |
| ) |
|
◆ Context() [2/3]
| IuvoUnity.DataStructs.Context.Context |
( |
ref ConcurrentDictionary< Enum, object > | contextDictionary | ) |
|
102 {
103 _data = new ConcurrentDictionary<Enum, object>(contextDictionary);
104 }
References _data.
◆ Context() [3/3]
| IuvoUnity.DataStructs.Context.Context |
( |
ref ConcurrentDictionary< Enum, object > | contextDictionary, |
|
|
ref ConcurrentDictionary< Enum, object > | eventDictionary ) |
107 {
108 _data = new ConcurrentDictionary<Enum, object>(contextDictionary);
109 _eventMap = new ConcurrentDictionary<Enum, object>(eventDictionary);
110 }
References _data, and _eventMap.
◆ ClearData()
| void IuvoUnity.DataStructs.Context.ClearData |
( |
| ) |
|
◆ ClearEvents()
| void IuvoUnity.DataStructs.Context.ClearEvents |
( |
| ) |
|
242 {
243 foreach (var kvp in _eventMap)
244 {
245 if (kvp.Value is FlexibleEvent fe)
246 {
247 fe.RemoveAllFlexibleEventListeners();
248 }
249 else if (kvp.Value is System.IDisposable disposable)
250 {
251 disposable.Dispose();
252 }
253 }
254 _eventMap.Clear();
255
256 }
References _eventMap.
Referenced by Dispose().
◆ CloneContext()
| Context IuvoUnity.DataStructs.Context.CloneContext |
( |
| ) |
|
159 {
160 var newDict = new ConcurrentDictionary<Enum, object>(_data);
161 var newEventDict = new ConcurrentDictionary<Enum, object>(_eventMap);
162 return new Context(ref newDict, ref newEventDict);
163 }
References _data, _eventMap, and Context().
◆ Dispose()
| void IuvoUnity.DataStructs.Context.Dispose |
( |
| ) |
|
◆ Get< T >()
| T IuvoUnity.DataStructs.Context.Get< T > |
( |
Enum | key | ) |
|
125 {
126 if (!ContextKeyGroups.IsValidKey(key))
127 throw new InvalidOperationException($"Invalid key type: {key.GetType().Name}");
128
129 if (_data.TryGetValue(key, out var value) && value is T t)
130 return t;
131
132 throw new KeyNotFoundException($"Key {key} not found or wrong type");
133 }
References _data, and IuvoUnity.DataStructs.ContextKeyGroups.IsValidKey().
◆ Has()
| bool IuvoUnity.DataStructs.Context.Has |
( |
Enum | key | ) |
|
153=> _data.ContainsKey(key);
References _data.
◆ HasEvent()
| bool IuvoUnity.DataStructs.Context.HasEvent |
( |
Enum | key | ) |
|
239=> _eventMap.ContainsKey(key);
References _eventMap.
◆ InvokeEvent()
| void IuvoUnity.DataStructs.Context.InvokeEvent |
( |
Enum | key | ) |
|
224 {
225 if (TryGetEvent(key, out FlexibleEvent evt))
226 {
227 evt.Invoke();
228 }
229 }
References TryGetEvent().
◆ InvokeEvent< T >()
232 {
233 if (TryGetEvent<T>(key, out FlexibleEvent<T> evt))
234 {
235 evt.Invoke(value);
236 }
237 }
References TryGetEvent().
◆ MergeContexts()
| void IuvoUnity.DataStructs.Context.MergeContexts |
( |
Context | other, |
|
|
bool | overwrite = true ) |
166 {
167 foreach (var kvp in other._data)
168 {
169 if (overwrite || !_data.ContainsKey(kvp.Key))
170 {
171 _data[kvp.Key] = kvp.Value;
172 }
173 }
174
175 foreach (var kvp in other._eventMap)
176 {
177 if (overwrite || !_eventMap.ContainsKey(kvp.Key))
178 {
179 _eventMap[kvp.Key] = kvp.Value;
180 }
181 }
182
183 }
References _data, _eventMap, and Context().
◆ RegisterEvent()
| void IuvoUnity.DataStructs.Context.RegisterEvent |
( |
Enum | key, |
|
|
FlexibleEvent | evt ) |
◆ RegisterEvent< T >()
◆ Remove()
| bool IuvoUnity.DataStructs.Context.Remove |
( |
Enum | key | ) |
|
154=> _data.TryRemove(key, out _);
References _data.
◆ RemoveEvent()
| bool IuvoUnity.DataStructs.Context.RemoveEvent |
( |
Enum | key | ) |
|
240=> _eventMap.TryRemove(key, out _);
References _eventMap.
◆ Set< T >()
| void IuvoUnity.DataStructs.Context.Set< T > |
( |
Enum | key, |
|
|
T | value ) |
◆ TryGet< T >()
| bool IuvoUnity.DataStructs.Context.TryGet< T > |
( |
Enum | key, |
|
|
out T | value ) |
136 {
137 if (!ContextKeyGroups.IsValidKey(key))
138 {
139 value = default;
140 return false;
141 }
142
143 if (_data.TryGetValue(key, out var obj) && obj is T t)
144 {
145 value = t;
146 return true;
147 }
148
149 value = default;
150 return false;
151 }
References _data, and IuvoUnity.DataStructs.ContextKeyGroups.IsValidKey().
◆ TryGetEvent()
| bool IuvoUnity.DataStructs.Context.TryGetEvent |
( |
Enum | key, |
|
|
out FlexibleEvent | evt ) |
199 {
200 if (_eventMap.TryGetValue(key, out var val) && val is FlexibleEvent e)
201 {
202 evt = e;
203 return true;
204 }
205
206 evt = null;
207 return false;
208 }
References _eventMap.
Referenced by InvokeEvent(), and InvokeEvent< T >().
◆ TryGetEvent< T >()
211 {
212 if (_eventMap.TryGetValue(key, out var val) && val is FlexibleEvent<T> e)
213 {
214 evt = e;
215 return true;
216 }
217
218 evt = null;
219 return false;
220 }
References _eventMap.
◆ _data
| ConcurrentDictionary<Enum, object> IuvoUnity.DataStructs.Context._data = new ConcurrentDictionary<Enum, object>() |
|
private |
◆ _eventMap
| ConcurrentDictionary<Enum, object> IuvoUnity.DataStructs.Context._eventMap = new ConcurrentDictionary<Enum, object>() |
|
private |
The documentation for this class was generated from the following file:
- D:/Unity/IuvoUnityCore/Assets/IuvoUnity/Runtime/DataStructs/Context.cs