1
This commit is contained in:
@@ -15,6 +15,10 @@ namespace BITKit
|
||||
void AddListener<T>(TKey key, Action<T> action);
|
||||
void Invoke<T>(TKey key, T value);
|
||||
void RemoveListener<T>(TKey key, Action<T> action);
|
||||
|
||||
void SetDirect(int key, object value);
|
||||
void GetDirect(int key, out object value);
|
||||
void GetDirect<T>(int key,out T value);
|
||||
}
|
||||
/// <summary>泛型数据库,主要使用方式为Get和Set</summary>
|
||||
public interface IDatabase
|
||||
@@ -25,8 +29,10 @@ namespace BITKit
|
||||
}
|
||||
public class GenericEvent : IGenericEvent<string>, IDatabase, IDiagnostics
|
||||
{
|
||||
Dictionary<string, List<object>> events = new();
|
||||
Dictionary<string, object> dictionary = new();
|
||||
private readonly Dictionary<int,object> _directDirection = new();
|
||||
|
||||
private readonly Dictionary<string, List<object>> events = new();
|
||||
private readonly Dictionary<string, object> dictionary = new();
|
||||
public const string defaultEventName = nameof(GenericEvent);
|
||||
public void AddListener<T>(Action<T> action) =>
|
||||
AddListener<T>(defaultEventName, action);
|
||||
@@ -120,6 +126,28 @@ namespace BITKit
|
||||
var list = events.Get(key);
|
||||
list.TryRemove(action);
|
||||
}
|
||||
|
||||
public void SetDirect(int key, object value)
|
||||
{
|
||||
_directDirection.Set(key, value);
|
||||
}
|
||||
|
||||
public void GetDirect(int key,out object value)
|
||||
{
|
||||
value = _directDirection.Get(key);
|
||||
}
|
||||
public void GetDirect<T>(int key,out T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = (T) _directDirection.Get(key);
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
value = default;
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugAllValues()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
|
Reference in New Issue
Block a user