public RequestRootBase Deserialize(XmlReader reader) { if (!reader.ReadToFollowing(RequestRootElementName)) { return(null); } if (!reader.ReadToFollowing(ActionElementName)) { return(null); } var typeName = reader[TypeAttributeName]; if (typeName == null) { return(null); } var type = BindToType(typeName); if (type == null) { throw new InvalidDataException(); // THROW AN EXCEPTION in this case } reader.ReadStartElement(); var serializer = new XmlSerializer(type); var action = serializer.Deserialize(reader); if (action == null) { return(null); } return(RequestRootHelper.CreateBase(action)); }
public static void Test() { var root1 = RequestRootHelper.Create(new ClassA { Value = "Some data" }); var root2 = RequestRootHelper.Create(new List <MyObject> { new MyObject { ObjectValue1 = "Object Value 1-1", ObjectValue2 = "Object Value 2-1" }, new MyObject { ObjectValue1 = "Object Value 1-2", ObjectValue2 = "Object Value 2-2" } }); var serializer = new RequestRootXmlSerializer(new[] { typeof(ClassA), typeof(List <ClassA>), typeof(MyObject), typeof(List <MyObject>) }); TestRootSerialization(root1, serializer); TestRootSerialization(root2, serializer); }