public void RecursionTest() { var templete = @" [@OrderId,@Price] @Name @CreateDate @Products #Products{ @Id @Code @Name @SubProducts} #Products$header{head@count } #Products$footer{ foot@count } #SubProducts{ sub @Id @Code @Name}"; var entity = new TestOrder(); entity.OrderId = TestHelper.RandomizeInt(); entity.Price = TestHelper.RandomizeInt() * TestHelper.RandomizeInt(); entity.Name = string.Concat("name-", TestHelper.RandomizeString()); entity.CreateDate = DateTime.Now; entity.Products = new List <TestProduct>() { new TestProduct() { Id = TestHelper.RandomizeInt(), Code = string.Concat("p-code-", TestHelper.RandomizeString()), Name = string.Concat("name-", TestHelper.RandomizeString()), SubProducts = new List <TestProduct>() { new TestProduct() { Id = TestHelper.RandomizeInt(), Code = string.Concat("sub-p-code-", TestHelper.RandomizeString()), Name = string.Concat("name-", TestHelper.RandomizeString()) }, new TestProduct() { Id = TestHelper.RandomizeInt(), Code = string.Concat("sub-p-code-", TestHelper.RandomizeString()), Name = string.Concat("name-", TestHelper.RandomizeString()) } } }, new TestProduct() { Id = TestHelper.RandomizeInt(), Code = string.Concat("p-code-", TestHelper.RandomizeString()), Name = string.Concat("name-", TestHelper.RandomizeString()) } }; Console.WriteLine(entity.ToXmlText(templete)); Console.WriteLine("============"); }