-Refactor
This commit is contained in:
@@ -9799,6 +9799,9 @@ Path '', line 1, position 1.");
|
|||||||
[Test]
|
[Test]
|
||||||
public void ChildClassWithProtectedOverridePlusJsonProperty_Serialize()
|
public void ChildClassWithProtectedOverridePlusJsonProperty_Serialize()
|
||||||
{
|
{
|
||||||
|
JsonObjectContract c = (JsonObjectContract)DefaultContractResolver.Instance.ResolveContract(typeof(ChildClassWithProtectedOverridePlusJsonProperty));
|
||||||
|
Assert.AreEqual(1, c.Properties.Count);
|
||||||
|
|
||||||
var propertyValue = "test";
|
var propertyValue = "test";
|
||||||
var testJson = @"{ 'MyProperty' : '" + propertyValue + "' }";
|
var testJson = @"{ 'MyProperty' : '" + propertyValue + "' }";
|
||||||
|
|
||||||
|
|||||||
@@ -117,13 +117,13 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
MethodInfo m = propertyInfo.GetGetMethod();
|
MethodInfo m = propertyInfo.GetGetMethod(true);
|
||||||
if (m != null)
|
if (m != null)
|
||||||
{
|
{
|
||||||
return m.GetBaseDefinition();
|
return m.GetBaseDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
m = propertyInfo.GetSetMethod();
|
m = propertyInfo.GetSetMethod(true);
|
||||||
if (m != null)
|
if (m != null)
|
||||||
{
|
{
|
||||||
return m.GetBaseDefinition();
|
return m.GetBaseDefinition();
|
||||||
@@ -1054,18 +1054,16 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MethodInfo subTypePropertyBaseDefinition = subTypeProperty.GetBaseDefinition();
|
Type subTypePropertyDeclaringType = subTypeProperty.GetBaseDefinition()?.DeclaringType ?? subTypeProperty.DeclaringType;
|
||||||
if (subTypePropertyBaseDefinition != null)
|
|
||||||
{
|
|
||||||
int index = initialProperties.IndexOf(p => p.Name == subTypeProperty.Name
|
|
||||||
&& p.IsVirtual()
|
|
||||||
&& p.GetBaseDefinition() != null
|
|
||||||
&& p.GetBaseDefinition().DeclaringType.IsAssignableFrom(subTypePropertyBaseDefinition.DeclaringType));
|
|
||||||
|
|
||||||
if (index == -1)
|
int index = initialProperties.IndexOf(p => p.Name == subTypeProperty.Name
|
||||||
{
|
&& p.IsVirtual()
|
||||||
initialProperties.Add(subTypeProperty);
|
&& (p.GetBaseDefinition()?.DeclaringType ?? p.DeclaringType).IsAssignableFrom(subTypePropertyDeclaringType));
|
||||||
}
|
|
||||||
|
// don't add a virtual property that has an override
|
||||||
|
if (index == -1)
|
||||||
|
{
|
||||||
|
initialProperties.Add(subTypeProperty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user