-Improved Portable40 assembly performance by using compiled expression reflection

-Fixed converting string JValues to enums with JToken.ToObject
This commit is contained in:
James Newton-King
2014-08-24 23:33:08 +12:00
parent dce6228b8f
commit 57ccaf00bf
15 changed files with 125 additions and 21 deletions
+15 -1
View File
@@ -1701,7 +1701,21 @@ namespace Newtonsoft.Json.Linq
{
if (JsonConvert.DefaultSettings == null)
{
PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(objectType);
bool isEnum;
PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(objectType, out isEnum);
if (isEnum && Type == JTokenType.String)
{
Type enumType = objectType.IsEnum() ? objectType : Nullable.GetUnderlyingType(objectType);
try
{
return Enum.Parse(enumType, (string)this, true);
}
catch (Exception ex)
{
throw new ArgumentException("Could not convert '{0}' to {1}.".FormatWith(CultureInfo.InvariantCulture, (string)this, enumType.Name), ex);
}
}
switch (typeCode)
{