static void QuickDynamicTest() { ArrayList al = new ArrayList(); al.Add(1); al.Add("abc"); List <int> lint = new List <int>() { 1, 2 }; Hashtable ht = new Hashtable(); ht.Add(1, "abc"); ChoSerializableDictionary <int, string> dict = new ChoSerializableDictionary <int, string>(); dict.Add(1, "abc"); List <ExpandoObject> objs = new List <ExpandoObject>(); dynamic rec1 = new ExpandoObject(); rec1.Id = 1; rec1.Name = "Mark"; rec1.IsActive = true; rec1.Message = new ChoCDATA("Test"); rec1.Array = al; rec1.Lint = lint; //rec1.HT = ht; rec1.Dict = dict; objs.Add(rec1); dynamic rec2 = new ExpandoObject(); rec2.Id = 2; rec2.Name = "Jason"; rec2.IsActive = true; rec2.Message = new ChoCDATA("Test"); objs.Add(rec2); StringBuilder sb = new StringBuilder(); using (var parser = new ChoXmlWriter(sb).WithXPath("Employees/Employee")) { parser.Write(objs); } Console.WriteLine(sb.ToString()); var a = ChoXmlReader.LoadText(sb.ToString()).ToArray(); var config = new ChoXmlRecordConfiguration(); //config.Configure(c => c.RootName = "Root"); Console.WriteLine(ChoXmlWriter.ToText(a.First(), config)); }
public static void QuickDynamicTest() { string expected = @"<Employees> <Employee> <Id>1</Id> <Name>Mark</Name> <IsActive>true</IsActive> <Message><![CDATA[Test]]></Message> <Array> <anyType xmlns:q1=""http://www.w3.org/2001/XMLSchema"" p3:type=""q1:int"" xmlns:p3=""http://www.w3.org/2001/XMLSchema-instance"">1</anyType> <anyType xmlns:q2=""http://www.w3.org/2001/XMLSchema"" p3:type=""q2:string"" xmlns:p3=""http://www.w3.org/2001/XMLSchema-instance"">abc</anyType> </Array> <Lint> <int>1</int> <int>2</int> </Lint> <Dict> <item> <key> <int>1</int> </key> <value> <string>abc</string> </value> </item> </Dict> </Employee> <Employee> <Id>2</Id> <Name>Jason</Name> <IsActive>true</IsActive> <Message><![CDATA[Test]]></Message> </Employee> </Employees>"; string actual = null; ArrayList al = new ArrayList(); al.Add(1); al.Add("abc"); List <int> lint = new List <int>() { 1, 2 }; Hashtable ht = new Hashtable(); ht.Add(1, "abc"); ChoSerializableDictionary <int, string> dict = new ChoSerializableDictionary <int, string>(); dict.Add(1, "abc"); List <ExpandoObject> objs = new List <ExpandoObject>(); dynamic rec1 = new ExpandoObject(); rec1.Id = 1; rec1.Name = "Mark"; rec1.IsActive = true; rec1.Message = new ChoCDATA("Test"); rec1.Array = al; rec1.Lint = lint; //rec1.HT = ht; rec1.Dict = dict; objs.Add(rec1); dynamic rec2 = new ExpandoObject(); rec2.Id = 2; rec2.Name = "Jason"; rec2.IsActive = true; rec2.Message = new ChoCDATA("Test"); objs.Add(rec2); StringBuilder sb = new StringBuilder(); using (var parser = new ChoXmlWriter(sb).WithXPath("Employees/Employee")) { parser.Write(objs); } actual = sb.ToString(); Assert.AreEqual(expected, actual); //var a = ChoXmlReader.LoadText(sb.ToString()).ToArray(); //var config = new ChoXmlRecordConfiguration(); ////config.Configure(c => c.RootName = "Root"); //Console.WriteLine(ChoXmlWriter.ToText(a.First(), config)); }