You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB
C#

5 months ago
namespace DS.Module.Core.Data
{
/// <summary>
/// 任务模块之间用于传入、获取数据的容器
/// </summary>
public class TaskFlowDataContext
{
private readonly Dictionary<string, object?> dataContext = new();
5 months ago
/// <summary>
///
/// </summary>
public TaskFlowDataContext(string key, object? value)
5 months ago
{
dataContext.Add(key, value);
}
5 months ago
/// <summary>
///
/// </summary>
public TaskFlowDataContext(params (string key, object? value)[] keyValues)
5 months ago
{
foreach (var item in keyValues)
{
dataContext.Add(item.key, item.value);
}
}
5 months ago
/// <summary>
///
/// </summary>
public void Set(string key, object? value)
5 months ago
{
if (ContainsKey(key))
{
dataContext[key] = value;
}
else
{
dataContext.Add(key, value);
}
}
/// <summary>
///
/// </summary>
public T? Get<T>(string key)
{
if (dataContext.ContainsKey(key))
{
5 months ago
var value = dataContext[key];
if (value is T t)
{
return t;
}
5 months ago
}
return default;
}
/// <summary>
///
/// </summary>
public bool ContainsKey(string key) => dataContext.ContainsKey(key);
}
}