Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeInstanceCollection.cs
Go to the documentation of this file.
1using System;
3
4namespace ReLogic.Utilities;
5
6internal class TypeInstanceCollection<BaseType> : IDisposable where BaseType : class
7{
9
10 private bool _disposedValue;
11
12 public void Register<T>(T instance) where T : BaseType
13 {
14 _services.Add(typeof(T), (BaseType)(object)instance);
15 }
16
17 public T Get<T>() where T : BaseType
18 {
20 {
21 return (T)value;
22 }
23 return default(T);
24 }
25
26 public void Remove<T>() where T : BaseType
27 {
29 }
30
31 public bool Has<T>() where T : BaseType
32 {
33 return _services.ContainsKey(typeof(T));
34 }
35
36 public bool Has(Type type)
37 {
39 }
40
41 public void IfHas<T>(Action<T> callback) where T : BaseType
42 {
44 {
45 callback((T)value);
46 }
47 }
48
49 public U IfHas<T, U>(Func<T, U> callback) where T : BaseType
50 {
52 {
53 return callback((T)value);
54 }
55 return default(U);
56 }
57
58 protected virtual void Dispose(bool disposing)
59 {
61 {
62 return;
63 }
64 if (disposing)
65 {
66 foreach (BaseType value in _services.Values)
67 {
69 {
70 disposable.Dispose();
71 }
72 }
74 }
75 _disposedValue = true;
76 }
77
78 public void Dispose()
79 {
80 Dispose(disposing: true);
81 }
82}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)