Removed Convert.ChangeType calls because of poor performance (DynamicReflectionDelegateFactory now uses IConvertible.ToTypeName, while ExpressionReflectionDelegateFactory uses Convert.ToTypeName). Method binder moved to a separate file and documented, + code style fixes.

This commit is contained in:
Alexey Skalozub
2016-09-10 20:19:22 +03:00
parent 95a4979ba4
commit deefe2e006
7 changed files with 391 additions and 242 deletions
@@ -362,9 +362,13 @@ namespace Newtonsoft.Json.Utilities
if (targetType.IsPrimitive())
{
expression = Expression.Call(
typeof(Convert).GetMethod("ChangeType", new[] { typeof(object), typeof(Type) }),
expression, Expression.Constant(targetType));
MethodInfo toTargetTypeMethod = typeof(Convert)
.GetMethod("To" + targetType.Name, new[] { typeof(object) });
if (toTargetTypeMethod != null)
{
expression = Expression.Call(toTargetTypeMethod, expression);
}
}
return Expression.Convert(expression, targetType);