1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-28 07:19:09 +02:00
MLEM/MLEM/Misc/GenericDataHolder.cs
2020-04-26 02:19:58 +02:00

33 lines
913 B
C#

using System;
using System.Collections.Generic;
namespace MLEM.Misc {
public class GenericDataHolder {
private Dictionary<string, object> data;
public void SetData(string key, object data) {
if (data == default) {
if (this.data != null)
this.data.Remove(key);
} else {
if (this.data == null)
this.data = new Dictionary<string, object>();
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() {
if (this.data == null)
return Array.Empty<string>();
return this.data.Keys;
}
}
}