1
- using RestSharp . Extensions ;
2
- using System ;
1
+ using System ;
3
2
using System . Collections ;
4
3
using System . Collections . Generic ;
5
4
using System . Globalization ;
6
5
using System . Linq ;
7
6
using System . Reflection ;
7
+ using RestSharp . Extensions ;
8
8
9
9
namespace RestSharp . Deserializers
10
10
{
@@ -37,34 +37,34 @@ public T Deserialize<T>(IRestResponse response)
37
37
{
38
38
object root = this . FindRoot ( response . Content ) ;
39
39
40
- target = ( T ) this . BuildList ( objType , root ) ;
40
+ target = ( T ) this . BuildList ( objType , root ) ;
41
41
}
42
42
else
43
43
{
44
44
object data = SimpleJson . DeserializeObject ( response . Content ) ;
45
45
46
- target = ( T ) this . BuildList ( objType , data ) ;
46
+ target = ( T ) this . BuildList ( objType , data ) ;
47
47
}
48
48
}
49
49
else if ( target is IDictionary )
50
50
{
51
51
object root = this . FindRoot ( response . Content ) ;
52
52
53
- target = ( T ) this . BuildDictionary ( target . GetType ( ) , root ) ;
53
+ target = ( T ) this . BuildDictionary ( target . GetType ( ) , root ) ;
54
54
}
55
55
else
56
56
{
57
57
object root = this . FindRoot ( response . Content ) ;
58
58
59
- target = ( T ) this . Map ( target , ( IDictionary < string , object > ) root ) ;
59
+ target = ( T ) this . Map ( target , ( IDictionary < string , object > ) root ) ;
60
60
}
61
61
62
62
return target ;
63
63
}
64
64
65
65
private object FindRoot ( string content )
66
66
{
67
- IDictionary < string , object > data = ( IDictionary < string , object > ) SimpleJson . DeserializeObject ( content ) ;
67
+ IDictionary < string , object > data = ( IDictionary < string , object > ) SimpleJson . DeserializeObject ( content ) ;
68
68
69
69
if ( this . RootElement . HasValue ( ) && data . ContainsKey ( this . RootElement ) )
70
70
{
@@ -89,7 +89,7 @@ private object Map(object target, IDictionary<string, object> data)
89
89
90
90
if ( attributes . Length > 0 )
91
91
{
92
- DeserializeAsAttribute attribute = ( DeserializeAsAttribute ) attributes [ 0 ] ;
92
+ DeserializeAsAttribute attribute = ( DeserializeAsAttribute ) attributes [ 0 ] ;
93
93
name = attribute . Name ;
94
94
}
95
95
else
@@ -117,7 +117,7 @@ private object Map(object target, IDictionary<string, object> data)
117
117
}
118
118
else
119
119
{
120
- currentData = ( IDictionary < string , object > ) currentData [ actualName ] ;
120
+ currentData = ( IDictionary < string , object > ) currentData [ actualName ] ;
121
121
}
122
122
}
123
123
@@ -132,11 +132,11 @@ private object Map(object target, IDictionary<string, object> data)
132
132
133
133
private IDictionary BuildDictionary ( Type type , object parent )
134
134
{
135
- IDictionary dict = ( IDictionary ) Activator . CreateInstance ( type ) ;
135
+ IDictionary dict = ( IDictionary ) Activator . CreateInstance ( type ) ;
136
136
Type keyType = type . GetGenericArguments ( ) [ 0 ] ;
137
137
Type valueType = type . GetGenericArguments ( ) [ 1 ] ;
138
138
139
- foreach ( KeyValuePair < string , object > child in ( IDictionary < string , object > ) parent )
139
+ foreach ( KeyValuePair < string , object > child in ( IDictionary < string , object > ) parent )
140
140
{
141
141
object key = keyType != typeof ( string )
142
142
? Convert . ChangeType ( child . Key , keyType , CultureInfo . InvariantCulture )
@@ -161,15 +161,15 @@ private IDictionary BuildDictionary(Type type, object parent)
161
161
162
162
private IList BuildList ( Type type , object parent )
163
163
{
164
- IList list = ( IList ) Activator . CreateInstance ( type ) ;
164
+ IList list = ( IList ) Activator . CreateInstance ( type ) ;
165
165
Type listType = type . GetInterfaces ( )
166
166
. First
167
167
( x => x . IsGenericType && x . GetGenericTypeDefinition ( ) == typeof ( IList < > ) ) ;
168
168
Type itemType = listType . GetGenericArguments ( ) [ 0 ] ;
169
169
170
170
if ( parent is IList )
171
171
{
172
- foreach ( object element in ( IList ) parent )
172
+ foreach ( object element in ( IList ) parent )
173
173
{
174
174
if ( itemType . IsPrimitive )
175
175
{
@@ -276,14 +276,14 @@ private object ConvertValue(Type type, object value)
276
276
277
277
if ( type == typeof ( DateTimeOffset ) )
278
278
{
279
- return ( DateTimeOffset ) dt ;
279
+ return ( DateTimeOffset ) dt ;
280
280
}
281
281
}
282
282
else if ( type == typeof ( decimal ) )
283
283
{
284
284
if ( value is double )
285
285
{
286
- return ( decimal ) ( ( double ) value ) ;
286
+ return ( decimal ) ( ( double ) value ) ;
287
287
}
288
288
289
289
if ( stringValue . Contains ( "e" ) )
@@ -343,7 +343,7 @@ private object ConvertValue(Type type, object value)
343
343
}
344
344
else if ( type == typeof ( JsonObject ) )
345
345
{
346
- // simplify JsonObject into a Dictionary<string, object>
346
+ // simplify JsonObject into a Dictionary<string, object>
347
347
return this . BuildDictionary ( typeof ( Dictionary < string , object > ) , value ) ;
348
348
}
349
349
else
@@ -359,9 +359,9 @@ private object CreateAndMap(Type type, object element)
359
359
{
360
360
object instance = Activator . CreateInstance ( type ) ;
361
361
362
- this . Map ( instance , ( IDictionary < string , object > ) element ) ;
362
+ this . Map ( instance , ( IDictionary < string , object > ) element ) ;
363
363
364
364
return instance ;
365
365
}
366
366
}
367
- }
367
+ }
0 commit comments