-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 -6
View File
@@ -187,13 +187,25 @@ namespace Newtonsoft.Json.Utilities
#endif
public static PrimitiveTypeCode GetTypeCode(Type t)
{
bool isEnum;
return GetTypeCode(t, out isEnum);
}
public static PrimitiveTypeCode GetTypeCode(Type t, out bool isEnum)
{
PrimitiveTypeCode typeCode;
if (TypeCodeMap.TryGetValue(t, out typeCode))
{
isEnum = false;
return typeCode;
}
if (t.IsEnum())
{
isEnum = true;
return GetTypeCode(Enum.GetUnderlyingType(t));
}
// performance?
if (ReflectionUtils.IsNullableType(t))
@@ -202,18 +214,15 @@ namespace Newtonsoft.Json.Utilities
if (nonNullable.IsEnum())
{
Type nullableUnderlyingType = typeof(Nullable<>).MakeGenericType(Enum.GetUnderlyingType(nonNullable));
isEnum = true;
return GetTypeCode(nullableUnderlyingType);
}
}
isEnum = false;
return PrimitiveTypeCode.Object;
}
public static PrimitiveTypeCode GetTypeCode(object o)
{
return GetTypeCode(o.GetType());
}
#if !(NETFX_CORE || PORTABLE)
public static TypeInformation GetTypeInformation(IConvertible convertable)
{
@@ -623,7 +632,7 @@ namespace Newtonsoft.Json.Utilities
public static bool IsInteger(object value)
{
switch (GetTypeCode(value))
switch (GetTypeCode(value.GetType()))
{
case PrimitiveTypeCode.SByte:
case PrimitiveTypeCode.Byte: