<ProjectNode>
<PrimaryNode Index=”1″ Code=”150000″ Name=”xxx省”>
<SecondNode Index=”2″ Code=”150100″ Name=”xxx市”>
<ThirdlyNode Index=”3″ Code=”150101″ Name=”xxx区”>
</ThirdlyNode>
</SecondNode>
</PrimaryNode>
</ProjectNode>
本人是这样写:
public class TreeConfigClass : ConfigInterface
{
public TreeConfigClass()
{
}
private List<ConfigInterface> _Node = new List<ConfigInterface>();
public int Count
{
get
{
if (_Node == null)
return 0;
return _Node.Count;
}
}
/// <summary>
/// 索引器
/// </summary>
/// <param name=”index”>数组索引</param>
/// <returns></returns>
public ConfigInterface this[int index]
{
get
{
if (_Node == null)
return null;
if (_Node.Count < 0)
return null;
return _Node[index];
}
set
{
if (_Node == null)
return;
_Node.Add(value);
}
}
public void Add(ConfigInterface ExTreeConfigClass)
{
_Node.Add(ExTreeConfigClass);
}
/// <summary>
/// 节点名称
/// </summary>
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
/// <summary>
/// 节点代码
/// </summary>
private string _Code;
public string Code
{
get { return _Code; }
set { _Code = value; }
}
/// <summary>
/// 序号
/// </summary>
private string _Index;
public string Index
{
get { return _Index; }
set { _Index = value; }
}
}
但是读取的时候
10
30
那是你没有实例化每一个节点,而是用一个节点对象加载每一个节点造成的