diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 7fc45ec3..1dc227bf 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.3.17307")] +[assembly: AssemblyFileVersion("6.0.3.17308")] diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index eb7463eb..76dbf66e 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -91,5 +91,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyFileVersion("6.0.3.17307")] +[assembly: AssemblyFileVersion("6.0.3.17308")] [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 5fa05f5c..ff88ee30 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -496,7 +496,7 @@ namespace Newtonsoft.Json.Serialization Type enumerableWrapper = typeof(DictionaryEnumerator<,>).MakeGenericType(keyType, valueType); ConstructorInfo constructors = enumerableWrapper.GetConstructors().First(); - MethodCall createEnumerableWrapper = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(constructors); + ObjectConstructor createEnumerableWrapper = JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(constructors); ExtensionDataGetter extensionDataGetter = o => { @@ -504,7 +504,7 @@ namespace Newtonsoft.Json.Serialization if (dictionary == null) return null; - return (IEnumerable>)createEnumerableWrapper(null, dictionary); + return (IEnumerable>)createEnumerableWrapper(dictionary); }; if (extensionDataAttribute.ReadData) diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index 35892a35..bca6477a 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -67,7 +67,7 @@ namespace Newtonsoft.Json.Serialization internal bool IsArray { get; private set; } internal bool ShouldCreateWrapper { get; private set; } internal bool CanDeserialize { get; private set; } - internal MethodCall ParametrizedCreator { get; private set; } + internal ObjectConstructor ParametrizedCreator { get; private set; } /// /// Initializes a new instance of the class. @@ -186,19 +186,19 @@ namespace Newtonsoft.Json.Serialization _isCollectionItemTypeNullableType = ReflectionUtils.IsNullableType(CollectionItemType); #if (NET20 || NET35) - // bug in .NET 2.0 & 3.5 that List> throws an error when adding null via IList.Add(object) - // wrapper will handle calling Add(T) instead - if (_isCollectionItemTypeNullableType - && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(List<>), out tempCollectionType) - || (IsArray && !IsMultidimensionalArray))) - { - ShouldCreateWrapper = true; - } + // bug in .NET 2.0 & 3.5 that List> throws an error when adding null via IList.Add(object) + // wrapper will handle calling Add(T) instead + if (_isCollectionItemTypeNullableType + && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(List<>), out tempCollectionType) + || (IsArray && !IsMultidimensionalArray))) + { + ShouldCreateWrapper = true; + } #endif #if !(NET20 || NET35 || NET40 || PORTABLE40) Type immutableCreatedType; - MethodCall immutableParameterizedCreator; + ObjectConstructor immutableParameterizedCreator; if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, CollectionItemType, out immutableCreatedType, out immutableParameterizedCreator)) { CreatedType = immutableCreatedType; diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index 9b455319..48bae167 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Serialization private Func _genericTemporaryDictionaryCreator; internal bool ShouldCreateWrapper { get; private set; } - internal MethodCall ParametrizedCreator { get; private set; } + internal ObjectConstructor ParametrizedCreator { get; private set; } /// /// Initializes a new instance of the class. @@ -138,20 +138,20 @@ namespace Newtonsoft.Json.Serialization _isDictionaryValueTypeNullableType = ReflectionUtils.IsNullableType(DictionaryValueType); #if (NET20 || NET35) - Type tempDictioanryType; + Type tempDictioanryType; - // bug in .NET 2.0 & 3.5 that Dictionary> throws an error when adding null via IDictionary[key] = object - // wrapper will handle calling Add(T) instead - if (_isDictionaryValueTypeNullableType - && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(Dictionary<,>), out tempDictioanryType))) - { - ShouldCreateWrapper = true; - } + // bug in .NET 2.0 & 3.5 that Dictionary> throws an error when adding null via IDictionary[key] = object + // wrapper will handle calling Add(T) instead + if (_isDictionaryValueTypeNullableType + && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(Dictionary<,>), out tempDictioanryType))) + { + ShouldCreateWrapper = true; + } #endif #if !(NET20 || NET35 || NET40 || PORTABLE40) Type immutableCreatedType; - MethodCall immutableParameterizedCreator; + ObjectConstructor immutableParameterizedCreator; if (ImmutableCollectionsUtils.TryBuildImmutableForDictionaryContract(underlyingType, DictionaryKeyType, DictionaryValueType, out immutableCreatedType, out immutableParameterizedCreator)) { CreatedType = immutableCreatedType; diff --git a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs index 6b13787f..97601ece 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs @@ -84,16 +84,7 @@ namespace Newtonsoft.Json.Serialization set { _overrideConstructor = value; - - if (value != null) - { - MethodCall ctor = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(value); - _overrideCreator = args => ctor(null, args); - } - else - { - _overrideCreator = null; - } + _overrideCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(value) : null; } } @@ -108,24 +99,16 @@ namespace Newtonsoft.Json.Serialization set { _parametrizedConstructor = value; - if (value != null) - { - MethodCall ctor = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(value); - _parametrizedCreator = args => ctor(null, args); - } - else - { - _parametrizedCreator = null; - } + _parametrizedCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(value) : null; } } /// /// Gets or sets the function used to create the object. When set this function will override . - /// This function can be called with a collection of arguments which are defined by the collection. + /// This function is called with a collection of arguments which are defined by the collection. /// /// The function used to create the object. - public Func OverrideCreator + public ObjectConstructor OverrideCreator { get { return _overrideCreator; } set @@ -135,7 +118,7 @@ namespace Newtonsoft.Json.Serialization } } - internal Func ParametrizedCreator + internal ObjectConstructor ParametrizedCreator { get { return _parametrizedCreator; } } @@ -153,8 +136,8 @@ namespace Newtonsoft.Json.Serialization private bool? _hasRequiredOrDefaultValueProperties; private ConstructorInfo _parametrizedConstructor; private ConstructorInfo _overrideConstructor; - private Func _overrideCreator; - private Func _parametrizedCreator; + private ObjectConstructor _overrideCreator; + private ObjectConstructor _parametrizedCreator; internal bool HasRequiredOrDefaultValueProperties { diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 4ae60ed2..d8b16ee3 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -471,7 +471,7 @@ namespace Newtonsoft.Json.Serialization if (createdFromNonDefaultCreator) { - return dictionaryContract.ParametrizedCreator(null, new object[] { dictionary }); + return dictionaryContract.ParametrizedCreator(dictionary); } else if (dictionary is IWrappedDictionary) { @@ -783,7 +783,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ else { // call constructor that takes IEnumerable - return arrayContract.ParametrizedCreator(null, new object[] {list}); + return arrayContract.ParametrizedCreator(list); } } else if (list is IWrappedCollection) @@ -1568,7 +1568,7 @@ To fix this error either change the environment to be fully trusted, change the } #endif - private object CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, Func creator, string id) + private object CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor creator, string id) { ValidationUtils.ArgumentNotNull(creator, "creator"); diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index 7749e9d0..18e6f7c5 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Utilities return false; } - public static MethodCall ResolveEnumableCollectionConstructor(Type collectionType, Type collectionItemType) + public static ObjectConstructor ResolveEnumableCollectionConstructor(Type collectionType, Type collectionItemType) { Type genericEnumerable = typeof(IEnumerable<>).MakeGenericType(collectionItemType); @@ -113,7 +113,7 @@ namespace Newtonsoft.Json.Utilities if (parameters.Count == 1) { if (genericEnumerable.IsAssignableFrom(parameters[0].ParameterType)) - return JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(constructor); + return JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(constructor); } } diff --git a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs index df013742..e6e6a34f 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs @@ -49,23 +49,33 @@ namespace Newtonsoft.Json.Utilities return dynamicMethod; } + public override ObjectConstructor CreateParametrizedConstructor(MethodBase method) + { + DynamicMethod dynamicMethod = CreateDynamicMethod(method.ToString(), typeof(object), new[] { typeof(object[]) }, method.DeclaringType); + ILGenerator generator = dynamicMethod.GetILGenerator(); + + GenerateCreateMethodCallIL(method, generator, 0); + + return (ObjectConstructor)dynamicMethod.CreateDelegate(typeof(ObjectConstructor)); + } + public override MethodCall CreateMethodCall(MethodBase method) { DynamicMethod dynamicMethod = CreateDynamicMethod(method.ToString(), typeof(object), new[] { typeof(object), typeof(object[]) }, method.DeclaringType); ILGenerator generator = dynamicMethod.GetILGenerator(); - GenerateCreateMethodCallIL(method, generator); + GenerateCreateMethodCallIL(method, generator, 1); return (MethodCall)dynamicMethod.CreateDelegate(typeof(MethodCall)); } - private void GenerateCreateMethodCallIL(MethodBase method, ILGenerator generator) + private void GenerateCreateMethodCallIL(MethodBase method, ILGenerator generator, int argsIndex) { ParameterInfo[] args = method.GetParameters(); Label argsOk = generator.DefineLabel(); - generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Ldarg, argsIndex); generator.Emit(OpCodes.Ldlen); generator.Emit(OpCodes.Ldc_I4, args.Length); generator.Emit(OpCodes.Beq, argsOk); @@ -84,7 +94,7 @@ namespace Newtonsoft.Json.Utilities { Type parameterType = args[i].ParameterType; - generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Ldarg, argsIndex); generator.Emit(OpCodes.Ldc_I4, i); generator.Emit(OpCodes.Ldelem_Ref); @@ -108,7 +118,7 @@ namespace Newtonsoft.Json.Utilities // parameter has value, get value from array again and unbox generator.MarkLabel(skipSettingDefault); - generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Ldarg, argsIndex); generator.Emit(OpCodes.Ldc_I4, i); generator.Emit(OpCodes.Ldelem_Ref); generator.UnboxIfNeeded(parameterType); diff --git a/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs b/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs index 9dfc68d1..a40bd611 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs @@ -116,8 +116,8 @@ namespace Newtonsoft.Json.Utilities Init(); return (CallSiteBinder)_getMemberCall(null, 0, name, context, _getCSharpArgumentInfoArray); #else - return Binder.GetMember( - CSharpBinderFlags.None, name, context, new[] {CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)}); + return Binder.GetMember( + CSharpBinderFlags.None, name, context, new[] {CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)}); #endif } @@ -127,12 +127,12 @@ namespace Newtonsoft.Json.Utilities Init(); return (CallSiteBinder)_setMemberCall(null, 0, name, context, _setCSharpArgumentInfoArray); #else - return Binder.SetMember( - CSharpBinderFlags.None, name, context, new[] - { - CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), - CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant, null) - }); + return Binder.SetMember( + CSharpBinderFlags.None, name, context, new[] + { + CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), + CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant, null) + }); #endif } } diff --git a/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs index 448a84b8..9e309f2b 100644 --- a/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/ExpressionReflectionDelegateFactory.cs @@ -27,6 +27,7 @@ using System; using System.Linq.Expressions; using System.Reflection; +using Newtonsoft.Json.Serialization; namespace Newtonsoft.Json.Utilities { @@ -39,6 +40,22 @@ namespace Newtonsoft.Json.Utilities get { return _instance; } } + public override ObjectConstructor CreateParametrizedConstructor(MethodBase method) + { + ValidationUtils.ArgumentNotNull(method, "method"); + + Type type = typeof(object); + + ParameterExpression argsParameterExpression = Expression.Parameter(typeof(object[]), "args"); + + Expression callExpression = BuildMethodCall(method, type, null, argsParameterExpression); + + LambdaExpression lambdaExpression = Expression.Lambda(typeof(ObjectConstructor), callExpression, argsParameterExpression); + + ObjectConstructor compiled = (ObjectConstructor)lambdaExpression.Compile(); + return compiled; + } + public override MethodCall CreateMethodCall(MethodBase method) { ValidationUtils.ArgumentNotNull(method, "method"); @@ -48,6 +65,16 @@ namespace Newtonsoft.Json.Utilities ParameterExpression targetParameterExpression = Expression.Parameter(type, "target"); ParameterExpression argsParameterExpression = Expression.Parameter(typeof(object[]), "args"); + Expression callExpression = BuildMethodCall(method, type, targetParameterExpression, argsParameterExpression); + + LambdaExpression lambdaExpression = Expression.Lambda(typeof(MethodCall), callExpression, targetParameterExpression, argsParameterExpression); + + MethodCall compiled = (MethodCall)lambdaExpression.Compile(); + return compiled; + } + + private Expression BuildMethodCall(MethodBase method, Type type, ParameterExpression targetParameterExpression, ParameterExpression argsParameterExpression) + { ParameterInfo[] parametersInfo = method.GetParameters(); Expression[] argsExpression = new Expression[parametersInfo.Length]; @@ -79,23 +106,23 @@ namespace Newtonsoft.Json.Utilities Expression callExpression; if (method.IsConstructor) { - callExpression = Expression.New((ConstructorInfo)method, argsExpression); + callExpression = Expression.New((ConstructorInfo) method, argsExpression); } else if (method.IsStatic) { - callExpression = Expression.Call((MethodInfo)method, argsExpression); + callExpression = Expression.Call((MethodInfo) method, argsExpression); } else { Expression readParameter = EnsureCastExpression(targetParameterExpression, method.DeclaringType); - callExpression = Expression.Call(readParameter, (MethodInfo)method, argsExpression); + callExpression = Expression.Call(readParameter, (MethodInfo) method, argsExpression); } if (method is MethodInfo) { - MethodInfo m = (MethodInfo)method; - if (m.ReturnType != typeof(void)) + MethodInfo m = (MethodInfo) method; + if (m.ReturnType != typeof (void)) callExpression = EnsureCastExpression(callExpression, type); else callExpression = Expression.Block(callExpression, Expression.Constant(null)); @@ -105,10 +132,7 @@ namespace Newtonsoft.Json.Utilities callExpression = EnsureCastExpression(callExpression, type); } - LambdaExpression lambdaExpression = Expression.Lambda(typeof(MethodCall), callExpression, targetParameterExpression, argsParameterExpression); - - MethodCall compiled = (MethodCall)lambdaExpression.Compile(); - return compiled; + return callExpression; } public override Func CreateDefaultConstructor(Type type) diff --git a/Src/Newtonsoft.Json/Utilities/FSharpUtils.cs b/Src/Newtonsoft.Json/Utilities/FSharpUtils.cs index 9f1428b0..0cedbdb3 100644 --- a/Src/Newtonsoft.Json/Utilities/FSharpUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/FSharpUtils.cs @@ -104,35 +104,35 @@ namespace Newtonsoft.Json.Utilities } } - public static MethodCall CreateSeq(Type t) + public static ObjectConstructor CreateSeq(Type t) { MethodInfo seqType = _ofSeq.MakeGenericMethod(t); - return JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(seqType); + return JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(seqType); } - public static MethodCall CreateMap(Type keyType, Type valueType) + public static ObjectConstructor CreateMap(Type keyType, Type valueType) { MethodInfo creatorDefinition = typeof (FSharpUtils).GetMethod("BuildMapCreator"); MethodInfo creatorGeneric = creatorDefinition.MakeGenericMethod(keyType, valueType); - return (MethodCall)creatorGeneric.Invoke(null, null); + return (ObjectConstructor)creatorGeneric.Invoke(null, null); } - public static MethodCall BuildMapCreator() + public static ObjectConstructor BuildMapCreator() { Type genericMapType = _mapType.MakeGenericType(typeof(TKey), typeof(TValue)); ConstructorInfo ctor = genericMapType.GetConstructor(new[] { typeof(IEnumerable>) }); - MethodCall ctorDelegate = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(ctor); + ObjectConstructor ctorDelegate = JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(ctor); - MethodCall creator = (target, args) => + ObjectConstructor creator = args => { // convert dictionary KeyValuePairs to Tuples IEnumerable> values = (IEnumerable>)args[0]; IEnumerable> tupleValues = values.Select(kv => new Tuple(kv.Key, kv.Value)); - return ctorDelegate(null, tupleValues); + return ctorDelegate(tupleValues); }; return creator; diff --git a/Src/Newtonsoft.Json/Utilities/ImmutableCollectionsUtils.cs b/Src/Newtonsoft.Json/Utilities/ImmutableCollectionsUtils.cs index 8893f6aa..307558b8 100644 --- a/Src/Newtonsoft.Json/Utilities/ImmutableCollectionsUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ImmutableCollectionsUtils.cs @@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Utilities new ImmutableCollectionTypeInfo(ImmutableDictionaryGenericTypeName, ImmutableDictionaryGenericTypeName, ImmutableDictionaryTypeName) }; - internal static bool TryBuildImmutableForArrayContract(Type underlyingType, Type collectionItemType, out Type createdType, out MethodCall parameterizedCreator) + internal static bool TryBuildImmutableForArrayContract(Type underlyingType, Type collectionItemType, out Type createdType, out ObjectConstructor parameterizedCreator) { if (underlyingType.IsGenericType()) { @@ -119,7 +119,7 @@ namespace Newtonsoft.Json.Utilities { createdType = createdTypeDefinition.MakeGenericType(collectionItemType); MethodInfo method = mb.MakeGenericMethod(collectionItemType); - parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(method); + parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(method); return true; } } @@ -131,7 +131,7 @@ namespace Newtonsoft.Json.Utilities return false; } - internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, out Type createdType, out MethodCall parameterizedCreator) + internal static bool TryBuildImmutableForDictionaryContract(Type underlyingType, Type keyItemType, Type valueItemType, out Type createdType, out ObjectConstructor parameterizedCreator) { if (underlyingType.IsGenericType()) { @@ -153,7 +153,7 @@ namespace Newtonsoft.Json.Utilities { createdType = createdTypeDefinition.MakeGenericType(keyItemType, valueItemType); MethodInfo method = mb.MakeGenericMethod(keyItemType, valueItemType); - parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(method); + parameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParametrizedConstructor(method); return true; } } diff --git a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs index a7e2dc46..2ebf601b 100644 --- a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs @@ -42,6 +42,17 @@ namespace Newtonsoft.Json.Utilities get { return _instance; } } + public override ObjectConstructor CreateParametrizedConstructor(MethodBase method) + { + ValidationUtils.ArgumentNotNull(method, "method"); + + ConstructorInfo c = method as ConstructorInfo; + if (c != null) + return c.Invoke; + + return a => method.Invoke(null, a); + } + public override MethodCall CreateMethodCall(MethodBase method) { ValidationUtils.ArgumentNotNull(method, "method"); diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs index cef1f29a..1d9ffc57 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionDelegateFactory.cs @@ -63,6 +63,7 @@ namespace Newtonsoft.Json.Utilities } public abstract MethodCall CreateMethodCall(MethodBase method); + public abstract ObjectConstructor CreateParametrizedConstructor(MethodBase method); public abstract Func CreateDefaultConstructor(Type type); public abstract Func CreateGet(PropertyInfo propertyInfo); public abstract Func CreateGet(FieldInfo fieldInfo);