Files
tnb.server/common/Tnb.Common/Models/DObject.cs

46 lines
1.0 KiB
C#

namespace Tnb.Core;
/// <summary>
/// 字典对象
/// </summary>
public class DObject : Dictionary<string, object>
{
public DObject() { }
public DObject(string key, object value)
{
Add(key, value);
}
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
{
}
public void AddCascade(string code, object value)
{
var keys = code.Split('.');
if (keys.Length == 1)
{
Add(code, value);
return;
}
for (int i = 0; i < keys.Length; i++)
{
DObject temp = this;
if (i < keys.Length - 1)
{
if (!ContainsKey(keys[i]))
{
temp = new DObject();
Add(keys[i], temp);
}
else
{
temp = (DObject)temp[keys[i]];
}
}
else
{
temp.Add(keys[i], value);
}
}
}
}