Skip to content

Commit

Permalink
Merge pull request #1 from jchannon/issue-15-fix
Browse files Browse the repository at this point in the history
added fix to this PR as described by @amccorma
  • Loading branch information
jasonmead authored Jul 28, 2016
2 parents bf5b50f + 4bb84f8 commit 10b6487
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/SimpleJson/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,10 +1358,7 @@ public virtual object DeserializeObject(object value, Type type)

return null;
}
if (type.IsEnum || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type).IsEnum))
{
return Enum.Parse(ReflectionUtils.IsNullableType(type) ? Nullable.GetUnderlyingType(type) : type, str, true);
}

if (type == typeof(string))
return str;

Expand All @@ -1385,6 +1382,17 @@ public virtual object DeserializeObject(object value, Type type)

bool valueIsLong = value is long;
bool valueIsDouble = value is double;
if (type.IsEnum)
{
if (value is double || value is int || value is long)
{
return Enum.ToObject(type, Convert.ToInt32(value.ToString()));
}
else if (value is string)
{
return Enum.Parse(type, value.ToString());
}
}
if ((valueIsLong && type == typeof(long)) || (valueIsDouble && type == typeof(double)))
return value;
if ((valueIsDouble && type != typeof(double)) || (valueIsLong && type != typeof(long)))
Expand Down

0 comments on commit 10b6487

Please sign in to comment.