private void Compose(DataRowNode node, StringBuilder sb) { foreach (KeyValuePair <string, DataRowNode> childPair in node.ChildDict) { sb.Append("\""); sb.Append(childPair.Key); sb.Append("\":"); if (childPair.Value == null) { sb.Append("null"); } else { sb.Append("{"); Append(sb, childPair.Value.Row); if (childPair.Value.ChildDict.Count > 0 || childPair.Value.ChildrenDict.Count > 0) { Compose(childPair.Value, sb); } sb.Remove(sb.Length - 1, 1); sb.Append("}"); } sb.Append(","); } foreach (KeyValuePair <string, ICollection <DataRowNode> > childrenPair in node.ChildrenDict) { sb.Append("\""); sb.Append(childrenPair.Key); sb.Append("\":["); if (childrenPair.Value.Count == 0) { } else { foreach (DataRowNode childNode in childrenPair.Value) { sb.Append("{"); Append(sb, childNode.Row); if (childNode.ChildDict.Count > 0 || childNode.ChildrenDict.Count > 0) { Compose(childNode, sb); } sb.Remove(sb.Length - 1, 1); sb.Append("}"); sb.Append(","); } sb.Remove(sb.Length - 1, 1); } sb.Append("]"); sb.Append(","); } }
private void Compose(DataRowNode node, XElement element) { foreach (KeyValuePair <string, DataRowNode> childPair in node.ChildDict) { XElement child = Convert(childPair.Value.Row, childPair.Key); element.Add(child); Compose(childPair.Value, child); } foreach (KeyValuePair <string, ICollection <DataRowNode> > childrenPair in node.ChildrenDict) { XElement children = new XElement(childrenPair.Key); foreach (DataRowNode childNode in childrenPair.Value) { XElement child = Convert(childNode.Row, childNode.Entity); children.Add(child); Compose(childNode, child); } element.Add(children); } }