using Mapster;
using SqlSugar;
namespace Tnb.Core;
///
/// 字典对象
///
public class DObject : Dictionary
{
public DObject() { }
public DObject(string key, object value)
{
Add(key, value);
}
public DObject(Dictionary dictionary) : base(dictionary)
{
}
///
/// 将平面结构转换为树形嵌套结构
///
/// 以.号分隔的多级路径
///
public void AddToCascade(string codePath, object value)
{
var keys = codePath.Split('.');
if (keys.Length == 1)
{
Add(codePath, value);
return;
}
DObject temp = this;
for (int i = 0; i < keys.Length; i++)
{
var key = keys[i];
if (i < keys.Length - 1)
{
var obj = new DObject();
temp[key] = obj;
temp = obj;
}
else
{
temp[key] = value;
}
}
}
}