This commit is contained in:
James Newton-King
2015-08-31 17:31:07 +12:00
parent 85e7968ed9
commit c28feca66b
5 changed files with 11 additions and 7 deletions
@@ -86,14 +86,14 @@ namespace Newtonsoft.Json.Serialization
if (property.DeclaringType != null && existingProperty.DeclaringType != null)
{
if (property.DeclaringType.IsSubclassOf(existingProperty.DeclaringType)
|| (existingProperty.DeclaringType.IsInterface && property.DeclaringType.ImplementInterface(existingProperty.DeclaringType)))
|| (existingProperty.DeclaringType.IsInterface() && property.DeclaringType.ImplementInterface(existingProperty.DeclaringType)))
{
// current property is on a derived class and hides the existing
Remove(existingProperty);
duplicateProperty = false;
}
if (existingProperty.DeclaringType.IsSubclassOf(property.DeclaringType)
|| (property.DeclaringType.IsInterface && existingProperty.DeclaringType.ImplementInterface(property.DeclaringType)))
|| (property.DeclaringType.IsInterface() && existingProperty.DeclaringType.ImplementInterface(property.DeclaringType)))
{
// current property is hidden by the existing so don't add it
return;
@@ -553,13 +553,12 @@ namespace Newtonsoft.Json.Utilities
public static bool ImplementInterface(this Type type, Type interfaceType)
{
for (Type currentType = type; currentType != null; currentType = currentType.BaseType)
for (Type currentType = type; currentType != null; currentType = currentType.BaseType())
{
Type[] interfaces = currentType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
IEnumerable<Type> interfaces = currentType.GetInterfaces();
foreach (Type i in interfaces)
{
if (interfaces[i] == interfaceType || (interfaces[i] != null && interfaces[i].ImplementInterface(interfaceType)))
if (i == interfaceType || (i != null && i.ImplementInterface(interfaceType)))
{
return true;
}