1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-27 23:09:10 +02:00
MLEM/MLEM/Misc/GenericDataHolder.cs

29 lines
767 B
C#

using System.Collections.Generic;
namespace MLEM.Misc {
public class GenericDataHolder {
private Dictionary<string, object> data;
public void SetData(string key, object data) {
if (this.data == null)
this.data = new Dictionary<string, object>();
if (data == default) {
this.data.Remove(key);
} else {
this.data[key] = data;
}
}
public T GetData<T>(string key) {
if (this.data != null && this.data.TryGetValue(key, out var val) && val is T t)
return t;
return default;
}
public IReadOnlyCollection<string> GetDataKeys() {
return this.data.Keys;
}
}
}