Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix to this PR as described by @amccorma #1

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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