Browse Source

fixed tree

master
jkpete 2 months ago
parent
commit
08c0d6177b
  1. 37
      addons/EGFramework/Module/GenerateTools/Templete/Variant/EGTree.cs

37
addons/EGFramework/Module/GenerateTools/Templete/Variant/EGTree.cs

@ -10,6 +10,7 @@ namespace EGFramework
public IEGTree GetParent(); public IEGTree GetParent();
public void SetParent(IEGTree tree); public void SetParent(IEGTree tree);
public IEnumerable<IEGTree> GetChilds(); public IEnumerable<IEGTree> GetChilds();
public IEGTree GetChild(string key);
public void AppendTree(IEGTree tree); public void AppendTree(IEGTree tree);
} }
@ -25,7 +26,7 @@ namespace EGFramework
public bool BoolValue { set; get; } public bool BoolValue { set; get; }
public IEGTree Parent { set; get; } public IEGTree Parent { set; get; }
public List<IEGTree> Childs { set; get; } = new List<IEGTree>(); public Dictionary<string,IEGTree> Childs { set; get; } = new Dictionary<string,IEGTree>();
public EGTree() public EGTree()
{ {
@ -37,14 +38,32 @@ namespace EGFramework
} }
public void AppendTree(IEGTree tree) public void AppendTree(IEGTree tree)
{
if (!Childs.ContainsKey(tree.Name))
{ {
tree.SetParent(this); tree.SetParent(this);
Childs.Add(tree); Childs.Add(tree.Name,tree);
}
}
public void AppendTree(string treeName)
{
if (!Childs.ContainsKey(treeName))
{
EGTree newTree = new EGTree(treeName);
newTree.SetParent(this);
Childs.Add(treeName, newTree);
}
}
public bool Contains(string name)
{
return Childs.ContainsKey(name);
} }
public virtual IEnumerable<IEGTree> GetChilds() public virtual IEnumerable<IEGTree> GetChilds()
{ {
return Childs; return Childs.Values;
} }
public virtual IEGTree GetParent() public virtual IEGTree GetParent()
@ -56,6 +75,18 @@ namespace EGFramework
{ {
this.Parent = tree; this.Parent = tree;
} }
public IEGTree GetChild(string key)
{
if (Childs.ContainsKey(key))
{
return Childs[key];
}
else
{
return null;
}
}
} }
public static class EGTreeFactory public static class EGTreeFactory

Loading…
Cancel
Save