public IList Deserialize(XContainer parent, string elementName, Type modelType, IList target) { if (target == null) { target = new List<object>(); } target = new XmlTransformer().Deserialize(parent, elementName, modelType, target); return target; }
public void DeserialzeTest() { MainObject mo = new MainObject() { Name = "name", Age = 33, Region = Region.Bbb, Child = new MainObject() { Name = "child", Age = 11, Region = Region.CcC }, }; mo.Boy.Name = "boy"; XmlTransformer trans = new XmlTransformer(); XDocument doc = new XDocument(); XElement root = new XElement("test"); doc.Add(root); trans.Serialize(mo, root); Debug.WriteLine(">>> Serializing..."); Debug.WriteLine(doc.ToString()); mo = new MainObject(); mo = (MainObject)trans.Deserialize(root, mo); Assert.AreEqual(mo.Name, "name"); Assert.AreEqual(mo.Region, Region.Bbb); Assert.AreEqual(mo.Age, 33); Assert.AreEqual(mo.Child.Name, "child"); Assert.AreEqual(mo.Boy.Name, "boy"); Assert.AreEqual(mo.Boy.Region, Region.AAA); Type t = typeof(MainObject); mo = (MainObject)trans.Deserialize(root, t); Assert.AreEqual(mo.Name, "name"); Assert.AreEqual(mo.Region, Region.Bbb); Assert.AreEqual(mo.Age, 33); Assert.AreEqual(mo.Child.Name, "child"); Assert.AreEqual(mo.Boy.Name, "boy"); Assert.AreEqual(mo.Boy.Region, Region.AAA); }