diff --git a/src/SimpleJson/SimpleJson.cs b/src/SimpleJson/SimpleJson.cs index 13485cb..ac3fdc9 100644 --- a/src/SimpleJson/SimpleJson.cs +++ b/src/SimpleJson/SimpleJson.cs @@ -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; @@ -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)))