private Node TransformManyChildrenNode(ManyChildrenNode node) { var children = node.Children; if (children == null) { return(new NoChildrenNode(node.Name)); } else { var childrenList = children.ToList(); switch (childrenList.Count) { case 0: return(new NoChildrenNode(node.Name)); case 1: return(new SingleChildNode(node.Name, Transform(childrenList[0]))); case 2: return(new TwoChildrenNode(node.Name, Transform(childrenList[0]), Transform(childrenList[1]))); } } return(node); }
private static async void Test(string filePath) { using (var scope = Container.BeginLifetimeScope()) { var testData = new ManyChildrenNode("root", new ManyChildrenNode("child1", new ManyChildrenNode("leaf1"), new ManyChildrenNode("child2", new ManyChildrenNode("leaf2")))); var nodeWriter = scope.Resolve <INodeWriter>(); await nodeWriter.WriteToFileAsync(testData, filePath); var result = File.ReadAllText(filePath); Console.WriteLine(result); Console.ReadKey(); } }