forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataContractSerializer.Deserialize.cs
More file actions
38 lines (34 loc) · 1.07 KB
/
DataContractSerializer.Deserialize.cs
File metadata and controls
38 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#if !LITE
using System;
using System.IO;
using System.Runtime.Serialization;
using ServiceStack.Text;
namespace ServiceStack.Serialization
{
public partial class DataContractSerializer
{
public object DeserializeFromString(string xml, Type type)
{
try
{
return XmlSerializer.DeserializeFromString(xml, type);
}
catch (Exception ex)
{
throw new SerializationException("DeserializeDataContract: Error converting type: " + ex.Message, ex);
}
}
public T DeserializeFromString<T>(string xml)
{
var type = typeof(T);
return (T)DeserializeFromString(xml, type);
}
public T DeserializeFromStream<T>(Stream stream) => (T)DeserializeFromStream(typeof(T), stream);
public object DeserializeFromStream(Type type, Stream stream)
{
var serializer = new System.Runtime.Serialization.DataContractSerializer(type);
return serializer.ReadObject(stream);
}
}
}
#endif