Fix calling constructors with ref and in parameters (#1728)
This commit is contained in:
@@ -1156,12 +1156,14 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// <returns>A <see cref="JsonContract"/> for the given type.</returns>
|
||||
protected virtual JsonContract CreateContract(Type objectType)
|
||||
{
|
||||
if (IsJsonPrimitiveType(objectType))
|
||||
Type t = ReflectionUtils.EnsureNotByRefType(objectType);
|
||||
|
||||
if (IsJsonPrimitiveType(t))
|
||||
{
|
||||
return CreatePrimitiveContract(objectType);
|
||||
}
|
||||
|
||||
Type t = ReflectionUtils.EnsureNotNullableType(objectType);
|
||||
t = ReflectionUtils.EnsureNotNullableType(t);
|
||||
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(t);
|
||||
|
||||
if (containerAttribute is JsonObjectAttribute)
|
||||
|
||||
@@ -238,7 +238,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
UnderlyingType = underlyingType;
|
||||
|
||||
// resolve ByRef types
|
||||
// typically comes from in and ref parameters on methods/ctors
|
||||
underlyingType = ReflectionUtils.EnsureNotByRefType(underlyingType);
|
||||
|
||||
IsNullable = ReflectionUtils.IsNullable(underlyingType);
|
||||
|
||||
NonNullableUnderlyingType = (IsNullable && ReflectionUtils.IsNullableType(underlyingType)) ? Nullable.GetUnderlyingType(underlyingType) : underlyingType;
|
||||
|
||||
CreatedType = NonNullableUnderlyingType;
|
||||
|
||||
@@ -275,6 +275,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
: t;
|
||||
}
|
||||
|
||||
public static Type EnsureNotByRefType(Type t)
|
||||
{
|
||||
return (t.IsByRef && t.HasElementType)
|
||||
? t.GetElementType()
|
||||
: t;
|
||||
}
|
||||
|
||||
public static bool IsGenericDefinition(Type type, Type genericInterfaceDefinition)
|
||||
{
|
||||
if (!type.IsGenericType())
|
||||
|
||||
Reference in New Issue
Block a user