-Fixed non-public base class properties being used instead of child class properties

This commit is contained in:
James Newton-King
2014-03-16 13:09:34 +13:00
parent abeea50c97
commit 1c018e7a09
5 changed files with 52 additions and 9 deletions
@@ -435,8 +435,8 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void EvaluateScan()
{
JObject o1 = new JObject{ {"Name", 1} };
JObject o2 = new JObject{ {"Name", 2} };
JObject o1 = new JObject { { "Name", 1 } };
JObject o2 = new JObject { { "Name", 2 } };
JArray a = new JArray(o1, o2);
IList<JToken> t = a.SelectTokens("$..Name").ToList();
@@ -655,7 +655,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
new JProperty("name", "The Rock"),
new JProperty("cast", new JArray(
new JObject(new JProperty("name", "Nick Cage")))))
);
);
IList<JToken> t = a.SelectTokens("[?(@.cast[?(@.name=='Will Smith')])].name").ToList();
Assert.IsNotNull(t);
@@ -75,4 +75,4 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.1.17109")]
[assembly: AssemblyFileVersion("6.0.1.17115")]
@@ -268,6 +268,44 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsTrue(JToken.DeepEquals(c.ExtensionData, c2.ExtensionData));
}
public class BaseClass
{
internal bool IsTransient { get; set; }
}
public class ChildClass : BaseClass
{
public new bool IsTransient { get; set; }
}
[Test]
public void NewProperty()
{
Assert.AreEqual(@"{""IsTransient"":true}", JsonConvert.SerializeObject(new ChildClass { IsTransient = true }));
var childClass = JsonConvert.DeserializeObject<ChildClass>(@"{""IsTransient"":true}");
Assert.AreEqual(true, childClass.IsTransient);
}
public class BaseClassVirtual
{
internal virtual bool IsTransient { get; set; }
}
public class ChildClassVirtual : BaseClassVirtual
{
public virtual new bool IsTransient { get; set; }
}
[Test]
public void NewPropertyVirtual()
{
Assert.AreEqual(@"{""IsTransient"":true}", JsonConvert.SerializeObject(new ChildClassVirtual { IsTransient = true }));
var childClass = JsonConvert.DeserializeObject<ChildClassVirtual>(@"{""IsTransient"":true}");
Assert.AreEqual(true, childClass.IsTransient);
}
[Test]
public void JsonSerializerProperties()
{
@@ -91,5 +91,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.1.17109")]
[assembly: AssemblyFileVersion("6.0.1.17115")]
[assembly: CLSCompliant(true)]
@@ -856,10 +856,15 @@ namespace Newtonsoft.Json.Utilities
}
else
{
// replace nonpublic properties for a child, but gotten from
// the parent with the one from the child
// the property gotten from the child will have access to private getter/setter
initialProperties[index] = subTypeProperty;
PropertyInfo childProperty = initialProperties[index];
// don't replace public child with private base
if (!IsPublic(childProperty))
{
// replace nonpublic properties for a child, but gotten from
// the parent with the one from the child
// the property gotten from the child will have access to private getter/setter
initialProperties[index] = subTypeProperty;
}
}
}
else