1- using RestSharp . Extensions ;
2- using System ;
1+ using System ;
32using System . Collections ;
43using System . Collections . Generic ;
54using System . Globalization ;
65using System . Linq ;
76using System . Reflection ;
7+ using RestSharp . Extensions ;
88
99namespace RestSharp . Deserializers
1010{
@@ -37,34 +37,34 @@ public T Deserialize<T>(IRestResponse response)
3737 {
3838 object root = this . FindRoot ( response . Content ) ;
3939
40- target = ( T ) this . BuildList ( objType , root ) ;
40+ target = ( T ) this . BuildList ( objType , root ) ;
4141 }
4242 else
4343 {
4444 object data = SimpleJson . DeserializeObject ( response . Content ) ;
4545
46- target = ( T ) this . BuildList ( objType , data ) ;
46+ target = ( T ) this . BuildList ( objType , data ) ;
4747 }
4848 }
4949 else if ( target is IDictionary )
5050 {
5151 object root = this . FindRoot ( response . Content ) ;
5252
53- target = ( T ) this . BuildDictionary ( target . GetType ( ) , root ) ;
53+ target = ( T ) this . BuildDictionary ( target . GetType ( ) , root ) ;
5454 }
5555 else
5656 {
5757 object root = this . FindRoot ( response . Content ) ;
5858
59- target = ( T ) this . Map ( target , ( IDictionary < string , object > ) root ) ;
59+ target = ( T ) this . Map ( target , ( IDictionary < string , object > ) root ) ;
6060 }
6161
6262 return target ;
6363 }
6464
6565 private object FindRoot ( string content )
6666 {
67- IDictionary < string , object > data = ( IDictionary < string , object > ) SimpleJson . DeserializeObject ( content ) ;
67+ IDictionary < string , object > data = ( IDictionary < string , object > ) SimpleJson . DeserializeObject ( content ) ;
6868
6969 if ( this . RootElement . HasValue ( ) && data . ContainsKey ( this . RootElement ) )
7070 {
@@ -89,7 +89,7 @@ private object Map(object target, IDictionary<string, object> data)
8989
9090 if ( attributes . Length > 0 )
9191 {
92- DeserializeAsAttribute attribute = ( DeserializeAsAttribute ) attributes [ 0 ] ;
92+ DeserializeAsAttribute attribute = ( DeserializeAsAttribute ) attributes [ 0 ] ;
9393 name = attribute . Name ;
9494 }
9595 else
@@ -117,7 +117,7 @@ private object Map(object target, IDictionary<string, object> data)
117117 }
118118 else
119119 {
120- currentData = ( IDictionary < string , object > ) currentData [ actualName ] ;
120+ currentData = ( IDictionary < string , object > ) currentData [ actualName ] ;
121121 }
122122 }
123123
@@ -132,11 +132,11 @@ private object Map(object target, IDictionary<string, object> data)
132132
133133 private IDictionary BuildDictionary ( Type type , object parent )
134134 {
135- IDictionary dict = ( IDictionary ) Activator . CreateInstance ( type ) ;
135+ IDictionary dict = ( IDictionary ) Activator . CreateInstance ( type ) ;
136136 Type keyType = type . GetGenericArguments ( ) [ 0 ] ;
137137 Type valueType = type . GetGenericArguments ( ) [ 1 ] ;
138138
139- foreach ( KeyValuePair < string , object > child in ( IDictionary < string , object > ) parent )
139+ foreach ( KeyValuePair < string , object > child in ( IDictionary < string , object > ) parent )
140140 {
141141 object key = keyType != typeof ( string )
142142 ? Convert . ChangeType ( child . Key , keyType , CultureInfo . InvariantCulture )
@@ -161,15 +161,15 @@ private IDictionary BuildDictionary(Type type, object parent)
161161
162162 private IList BuildList ( Type type , object parent )
163163 {
164- IList list = ( IList ) Activator . CreateInstance ( type ) ;
164+ IList list = ( IList ) Activator . CreateInstance ( type ) ;
165165 Type listType = type . GetInterfaces ( )
166166 . First
167167 ( x => x . IsGenericType && x . GetGenericTypeDefinition ( ) == typeof ( IList < > ) ) ;
168168 Type itemType = listType . GetGenericArguments ( ) [ 0 ] ;
169169
170170 if ( parent is IList )
171171 {
172- foreach ( object element in ( IList ) parent )
172+ foreach ( object element in ( IList ) parent )
173173 {
174174 if ( itemType . IsPrimitive )
175175 {
@@ -276,14 +276,14 @@ private object ConvertValue(Type type, object value)
276276
277277 if ( type == typeof ( DateTimeOffset ) )
278278 {
279- return ( DateTimeOffset ) dt ;
279+ return ( DateTimeOffset ) dt ;
280280 }
281281 }
282282 else if ( type == typeof ( decimal ) )
283283 {
284284 if ( value is double )
285285 {
286- return ( decimal ) ( ( double ) value ) ;
286+ return ( decimal ) ( ( double ) value ) ;
287287 }
288288
289289 if ( stringValue . Contains ( "e" ) )
@@ -343,7 +343,7 @@ private object ConvertValue(Type type, object value)
343343 }
344344 else if ( type == typeof ( JsonObject ) )
345345 {
346- // simplify JsonObject into a Dictionary<string, object>
346+ // simplify JsonObject into a Dictionary<string, object>
347347 return this . BuildDictionary ( typeof ( Dictionary < string , object > ) , value ) ;
348348 }
349349 else
@@ -359,9 +359,9 @@ private object CreateAndMap(Type type, object element)
359359 {
360360 object instance = Activator . CreateInstance ( type ) ;
361361
362- this . Map ( instance , ( IDictionary < string , object > ) element ) ;
362+ this . Map ( instance , ( IDictionary < string , object > ) element ) ;
363363
364364 return instance ;
365365 }
366366 }
367- }
367+ }
0 commit comments