How to deserialize an XML with information about a custom ob
I was able to serialize a List of objects (List) using this code:<br /><br />Hide Copy Code<br /><br /><strong>public static string Serialize(object obj)<br />{<br /> using (MemoryStream memoryStream = new MemoryStream())<br /> using (StreamReader reader = new StreamReader(memoryStream))<br /> {<br /> DataContractSerializer serializer = new DataContractSerializer(obj.GetType());<br /> serializer.WriteObject(memoryStream, obj);<br /> memoryStream.Position = 0;<br /> return reader.ReadToEnd();<br /> }<br />}</strong><br /><br /><br />However, I'm not able to deserialize using this code:<br /><br />Hide Copy Code<br /><br /> <strong>public static object Deserialize(string xml, Type toType)<br />{<br /> using (Stream stream = new MemoryStream())<br /> {<br /> byte[] data = System.Text.Encoding.UTF8.GetBytes(xml);<br /> stream.Write(data, 0, data.Length);<br /> stream.Position = 0;<br /> DataContractSerializer deserializer = new DataContractSerializer(toType);<br /> return deserializer.ReadObject(stream);<br /> }<br />}</strong><br /><br /><br />I'm not able to understand the problem. I'm using the last method by calling it with:<br /><br />Deserialize(SerializedObject, List), but I'm getting an error saying <strong>List is a type, which is not valid in the given context</strong><br /><br />Could anyone help? I'm a bit over my head with this.