-Fixed allowing static Specified properties
This commit is contained in:
@@ -701,11 +701,14 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
public string Prop3 { get; set; }
|
public string Prop3 { get; set; }
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public string Prop4 { get; set; }
|
public string Prop4 { get; set; }
|
||||||
|
[JsonProperty]
|
||||||
|
public string Prop5 { get; set; }
|
||||||
|
|
||||||
public bool Prop1Specified;
|
public bool Prop1Specified;
|
||||||
public bool Prop2Specified { get; set; }
|
public bool Prop2Specified { get; set; }
|
||||||
public static bool Prop3Specified { get; set; }
|
public static bool Prop3Specified { get; set; }
|
||||||
public event System.Func<bool> Prop4Specified;
|
public event System.Func<bool> Prop4Specified;
|
||||||
|
public static bool Prop5Specified;
|
||||||
|
|
||||||
protected virtual bool OnProp4Specified()
|
protected virtual bool OnProp4Specified()
|
||||||
{
|
{
|
||||||
@@ -736,6 +739,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
var property4 = contract.Properties["Prop4"];
|
var property4 = contract.Properties["Prop4"];
|
||||||
Assert.AreEqual(null, property4.GetIsSpecified);
|
Assert.AreEqual(null, property4.GetIsSpecified);
|
||||||
Assert.AreEqual(null, property4.SetIsSpecified);
|
Assert.AreEqual(null, property4.SetIsSpecified);
|
||||||
|
|
||||||
|
var property5 = contract.Properties["Prop5"];
|
||||||
|
Assert.AreEqual(null, property5.GetIsSpecified);
|
||||||
|
Assert.AreEqual(null, property5.SetIsSpecified);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -760,6 +767,10 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
var property4 = contract.Properties["Prop4"];
|
var property4 = contract.Properties["Prop4"];
|
||||||
Assert.AreEqual(null, property4.GetIsSpecified);
|
Assert.AreEqual(null, property4.GetIsSpecified);
|
||||||
Assert.AreEqual(null, property4.SetIsSpecified);
|
Assert.AreEqual(null, property4.SetIsSpecified);
|
||||||
|
|
||||||
|
var property5 = contract.Properties["Prop5"];
|
||||||
|
Assert.AreEqual(null, property5.GetIsSpecified);
|
||||||
|
Assert.AreEqual(null, property5.SetIsSpecified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1602,10 +1602,10 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private void SetIsSpecifiedActions(JsonProperty property, MemberInfo member, bool allowNonPublicAccess)
|
private void SetIsSpecifiedActions(JsonProperty property, MemberInfo member, bool allowNonPublicAccess)
|
||||||
{
|
{
|
||||||
MemberInfo specifiedMember = member.DeclaringType.GetProperty(member.Name + JsonTypeReflector.SpecifiedPostfix);
|
MemberInfo specifiedMember = member.DeclaringType.GetProperty(member.Name + JsonTypeReflector.SpecifiedPostfix, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
if (specifiedMember == null)
|
if (specifiedMember == null)
|
||||||
{
|
{
|
||||||
specifiedMember = member.DeclaringType.GetField(member.Name + JsonTypeReflector.SpecifiedPostfix);
|
specifiedMember = member.DeclaringType.GetField(member.Name + JsonTypeReflector.SpecifiedPostfix, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specifiedMember == null || ReflectionUtils.GetMemberUnderlyingType(specifiedMember) != typeof(bool))
|
if (specifiedMember == null || ReflectionUtils.GetMemberUnderlyingType(specifiedMember) != typeof(bool))
|
||||||
|
|||||||
@@ -345,7 +345,13 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static MemberInfo GetField(this Type type, string member, BindingFlags bindingFlags)
|
public static MemberInfo GetField(this Type type, string member, BindingFlags bindingFlags)
|
||||||
{
|
{
|
||||||
return type.GetTypeInfo().GetDeclaredField(member);
|
MemberInfo field = type.GetTypeInfo().GetDeclaredField(member);
|
||||||
|
if (field == null || !TestAccessibility(field, bindingFlags))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags bindingFlags)
|
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags bindingFlags)
|
||||||
@@ -426,7 +432,13 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags)
|
public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags)
|
||||||
{
|
{
|
||||||
return type.GetTypeInfo().GetDeclaredProperty(name);
|
PropertyInfo property = type.GetTypeInfo().GetDeclaredProperty(name);
|
||||||
|
if (property == null || !TestAccessibility(property, bindingFlags))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<FieldInfo> GetFields(this Type type)
|
public static IEnumerable<FieldInfo> GetFields(this Type type)
|
||||||
|
|||||||
Reference in New Issue
Block a user