forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyValueDataContractDeserializer.cs
More file actions
48 lines (41 loc) · 1.66 KB
/
KeyValueDataContractDeserializer.cs
File metadata and controls
48 lines (41 loc) · 1.66 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
39
40
41
42
43
44
45
46
47
48
#if !(SL5 || __IOS__ || XBOX || ANDROID || PCL)
using System;
using System.Collections.Generic;
using ServiceStack.Web;
namespace ServiceStack.Serialization
{
public class KeyValueDataContractDeserializer
{
public static KeyValueDataContractDeserializer Instance = new KeyValueDataContractDeserializer();
readonly Dictionary<Type, StringMapTypeDeserializer> typeStringMapSerializerMap
= new Dictionary<Type, StringMapTypeDeserializer>();
public object Parse(IDictionary<string, string> keyValuePairs, Type returnType)
{
return GetOrAddStringMapTypeDeserializer(returnType)
.CreateFromMap(keyValuePairs);
}
public object Parse(INameValueCollection nameValues, Type returnType)
{
return GetOrAddStringMapTypeDeserializer(returnType)
.CreateFromMap(nameValues);
}
private StringMapTypeDeserializer GetOrAddStringMapTypeDeserializer(Type returnType)
{
StringMapTypeDeserializer stringMapTypeDeserializer;
lock (typeStringMapSerializerMap)
{
if (!typeStringMapSerializerMap.TryGetValue(returnType, out stringMapTypeDeserializer))
{
stringMapTypeDeserializer = new StringMapTypeDeserializer(returnType);
typeStringMapSerializerMap.Add(returnType, stringMapTypeDeserializer);
}
}
return stringMapTypeDeserializer;
}
public To Parse<To>(IDictionary<string, string> keyValuePairs)
{
return (To)Parse(keyValuePairs, typeof(To));
}
}
}
#endif