这段树结构代码已经写了三四年。写的过程中经过反复修改,目前在自己的程序中以及比较成熟,在.net4下运行,有需要的人可以拿去。
主要面对字符串保存处理的问题,节点中考虑到扩展性也加入了object对象属性。节点本身使用了大量的字符串。
这篇文章里是底层的树节点以及相关调用代码。这个类是两三年之前在网上找到扩展的,对原作者表示感谢,现在搜了下找不到源了。
主要面对字符串保存处理的问题,节点中考虑到扩展性也加入了object对象属性。节点本身使用了大量的字符串。
这篇文章里是底层的树节点以及相关调用代码。这个类是两三年之前在网上找到扩展的,对原作者表示感谢,现在搜了下找不到源了。
树节点代码:
public class MultTreeNode
{
#region members
private int parentId;
private int selfId;
protected String nodeName;
protected Object obj;
protected MultTreeNode parentNode;
protected List<MultTreeNode> childList;
#endregion members
#region contrustion
public MultTreeNode()
{
init();
}
public MultTreeNode(MultTreeNode parentNode)
{
init(parentNode);
}
public void init(MultTreeNode pNode = null)
{
if (childList == null)
childList = new List<MultTreeNode>();
parentId = 0;
selfId = 0;
nodeName = "";
obj = null;
if (pNode != null)
{
nodeName = pNode.getNodeName();
if (pNode.getObj() != null)
obj = new Hashtable((Hashtable)pNode.getObj());
parentNode = pNode.getParentNode();
if (pNode.getChildList() != null)
childList = new List<MultTreeNode>(pNode.getChildList());
}
}
#endregion contrustion
#region check node
public bool isLeaf()
{
return childList == null || childList.Count == 0;
}
public bool isRoot()
{
return parentNode == null;
}
/// <summary>
/// check exist of child node.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool ExistChildNode(string name)//,bool IgnoreCase = false
{
bool bRet = false;
foreach (MultTreeNode node in childList)
{
if (node.nodeName == name)
{
bRet = true;
break;
}
}
return bRet;
}
#endregion check node
#region insert
/// <summary>
/// insert child node to one node(this).
/// </summary>
/// <param name="name">new child node name.</param>
/// <param name="path"></param>
/// <param name="newnode">can be null. no use I think.</param>
/// <returns&g