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
41 lines (35 loc) · 1.47 KB
/
KeyValueDataContractDeserializer.cs
File metadata and controls
41 lines (35 loc) · 1.47 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
#if !SILVERLIGHT && !MONOTOUCH && !XBOX
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace ServiceStack.ServiceModel.Serialization
{
public class KeyValueDataContractDeserializer
{
public static KeyValueDataContractDeserializer Instance = new KeyValueDataContractDeserializer();
public object Parse(NameValueCollection nameValues, Type returnType)
{
return Parse(nameValues.ToDictionary(), returnType);
}
readonly Dictionary<Type, StringMapTypeDeserializer> typeStringMapSerializerMap
= new Dictionary<Type, StringMapTypeDeserializer>();
public object Parse(IDictionary<string, string> keyValuePairs, Type returnType)
{
StringMapTypeDeserializer stringMapTypeDeserializer;
lock (typeStringMapSerializerMap)
{
if (!typeStringMapSerializerMap.TryGetValue(returnType, out stringMapTypeDeserializer))
{
stringMapTypeDeserializer = new StringMapTypeDeserializer(returnType);
typeStringMapSerializerMap.Add(returnType, stringMapTypeDeserializer);
}
}
return stringMapTypeDeserializer.CreateFromMap(keyValuePairs);
}
public To Parse<To>(IDictionary<string, string> keyValuePairs)
{
return (To)Parse(keyValuePairs, typeof(To));
}
}
}
#endif