Skip to content

Commit

Permalink
Undo cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DixonDs committed Aug 24, 2015
1 parent b215a4e commit 98863df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
15 changes: 8 additions & 7 deletions RestSharp.Tests/JsonTests.cs
Expand Up @@ -12,19 +12,19 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.

#endregion License
#endregion

using NUnit.Framework;
using RestSharp.Deserializers;
using RestSharp.Tests.SampleClasses;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using NUnit.Framework;
using RestSharp.Deserializers;
using RestSharp.Tests.SampleClasses;

namespace RestSharp.Tests
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public void Can_Deserialize_List_of_Guid()
data["Ids"] = new JsonArray { id1, id2 };

JsonDeserializer d = new JsonDeserializer();
RestResponse response = new RestResponse { Content = data.ToString() };
RestResponse response = new RestResponse { Content = data.ToString() };
GuidList p = d.Deserialize<GuidList>(response);

Assert.AreEqual(2, p.Ids.Count);
Expand Down Expand Up @@ -792,6 +792,7 @@ public void Can_Deserialize_Dictionary_with_Null()
Assert.IsNull(dictionary["Null"]);
}


private static string CreateJsonWithUnderscores()
{
JsonObject doc = new JsonObject();
Expand Down Expand Up @@ -1025,4 +1026,4 @@ private static T GetPayLoad<T>(string fileName)
return d.Deserialize<T>(response);
}
}
}
}
36 changes: 18 additions & 18 deletions RestSharp/Deserializers/JsonDeserializer.cs
@@ -1,10 +1,10 @@
using RestSharp.Extensions;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using RestSharp.Extensions;

namespace RestSharp.Deserializers
{
Expand Down Expand Up @@ -37,34 +37,34 @@ public T Deserialize<T>(IRestResponse response)
{
object root = this.FindRoot(response.Content);

target = (T)this.BuildList(objType, root);
target = (T) this.BuildList(objType, root);
}
else
{
object data = SimpleJson.DeserializeObject(response.Content);

target = (T)this.BuildList(objType, data);
target = (T) this.BuildList(objType, data);
}
}
else if (target is IDictionary)
{
object root = this.FindRoot(response.Content);

target = (T)this.BuildDictionary(target.GetType(), root);
target = (T) this.BuildDictionary(target.GetType(), root);
}
else
{
object root = this.FindRoot(response.Content);

target = (T)this.Map(target, (IDictionary<string, object>)root);
target = (T) this.Map(target, (IDictionary<string, object>) root);
}

return target;
}

private object FindRoot(string content)
{
IDictionary<string, object> data = (IDictionary<string, object>)SimpleJson.DeserializeObject(content);
IDictionary<string, object> data = (IDictionary<string, object>) SimpleJson.DeserializeObject(content);

if (this.RootElement.HasValue() && data.ContainsKey(this.RootElement))
{
Expand All @@ -89,7 +89,7 @@ private object Map(object target, IDictionary<string, object> data)

if (attributes.Length > 0)
{
DeserializeAsAttribute attribute = (DeserializeAsAttribute)attributes[0];
DeserializeAsAttribute attribute = (DeserializeAsAttribute) attributes[0];
name = attribute.Name;
}
else
Expand Down Expand Up @@ -117,7 +117,7 @@ private object Map(object target, IDictionary<string, object> data)
}
else
{
currentData = (IDictionary<string, object>)currentData[actualName];
currentData = (IDictionary<string, object>) currentData[actualName];
}
}

Expand All @@ -132,11 +132,11 @@ private object Map(object target, IDictionary<string, object> data)

private IDictionary BuildDictionary(Type type, object parent)
{
IDictionary dict = (IDictionary)Activator.CreateInstance(type);
IDictionary dict = (IDictionary) Activator.CreateInstance(type);
Type keyType = type.GetGenericArguments()[0];
Type valueType = type.GetGenericArguments()[1];

foreach (KeyValuePair<string, object> child in (IDictionary<string, object>)parent)
foreach (KeyValuePair<string, object> child in (IDictionary<string, object>) parent)
{
object key = keyType != typeof(string)
? Convert.ChangeType(child.Key, keyType, CultureInfo.InvariantCulture)
Expand All @@ -161,15 +161,15 @@ private IDictionary BuildDictionary(Type type, object parent)

private IList BuildList(Type type, object parent)
{
IList list = (IList)Activator.CreateInstance(type);
IList list = (IList) Activator.CreateInstance(type);
Type listType = type.GetInterfaces()
.First
(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>));
Type itemType = listType.GetGenericArguments()[0];

if (parent is IList)
{
foreach (object element in (IList)parent)
foreach (object element in (IList) parent)
{
if (itemType.IsPrimitive)
{
Expand Down Expand Up @@ -276,14 +276,14 @@ private object ConvertValue(Type type, object value)

if (type == typeof(DateTimeOffset))
{
return (DateTimeOffset)dt;
return (DateTimeOffset) dt;
}
}
else if (type == typeof(decimal))
{
if (value is double)
{
return (decimal)((double)value);
return (decimal) ((double) value);
}

if (stringValue.Contains("e"))
Expand Down Expand Up @@ -343,7 +343,7 @@ private object ConvertValue(Type type, object value)
}
else if (type == typeof(JsonObject))
{
// simplify JsonObject into a Dictionary<string, object>
// simplify JsonObject into a Dictionary<string, object>
return this.BuildDictionary(typeof(Dictionary<string, object>), value);
}
else
Expand All @@ -359,9 +359,9 @@ private object CreateAndMap(Type type, object element)
{
object instance = Activator.CreateInstance(type);

this.Map(instance, (IDictionary<string, object>)element);
this.Map(instance, (IDictionary<string, object>) element);

return instance;
}
}
}
}

0 comments on commit 98863df

Please sign in to comment.