private void AddChildes(TreeNode parent, StringBuilder sb)
{
string cfg = new ClientConfig().Serialize(parent);
if (parent.Nodes.Count > 0)
{
bool addComma = cfg.Length > 2;
int index = cfg.LastIndexOf("}");
sb.Append(cfg.Substring(0, index));
sb.Append(addComma ? ",":"").Append("children:[");
foreach (TreeNodeBase node in parent.Nodes)
{
node.Owner = this;
if (node is TreeNode)
{
TreeNode treeNode = (TreeNode) node;
this.AddChildes(treeNode, sb);
}
else
{
sb.Append(new ClientConfig().Serialize(node));
}
sb.Append(",");
}
if (sb[sb.Length - 1] == ',')
{
sb.Remove(sb.Length - 1, 1);
}
sb.Append("");
sb.Append("]}");
}
else
{
sb.Append(cfg);
}
}