-Misc refactoring
This commit is contained in:
@@ -282,7 +282,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
value = CreateJToken(reader);
|
||||
}
|
||||
else if (typeof(IDictionary).IsAssignableFrom(objectType) || ReflectionUtils.ImplementsGenericInterfaceDefinition(objectType, typeof(IDictionary<,>)))
|
||||
else if (typeof(IDictionary).IsAssignableFrom(objectType) || ReflectionUtils.ImplementsGenericDefinition(objectType, typeof(IDictionary<,>)))
|
||||
{
|
||||
if (existingValue == null)
|
||||
value = CreateAndPopulateDictionary(reader, objectType);
|
||||
@@ -493,7 +493,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
currentValue = ReflectionUtils.GetMemberValue(memberMapping.Member, target);
|
||||
|
||||
useExistingValue = (currentValue != null && !memberType.IsArray && !ReflectionUtils.InheritsGenericClassDefinition(memberType, typeof(ReadOnlyCollection<>)));
|
||||
useExistingValue = (currentValue != null && !memberType.IsArray && !ReflectionUtils.InheritsGenericDefinition(memberType, typeof(ReadOnlyCollection<>)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return true;
|
||||
else if (typeof(IList).IsAssignableFrom(type))
|
||||
return true;
|
||||
else if (ReflectionUtils.ImplementsGenericInterfaceDefinition(type, typeof(IList<>)))
|
||||
else if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(IList<>)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@@ -371,7 +371,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(list, "list");
|
||||
|
||||
Type collectionDefinition;
|
||||
if (ReflectionUtils.ImplementsGenericInterfaceDefinition(list.GetType(), typeof(ICollection<>), out collectionDefinition))
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(list.GetType(), typeof(ICollection<>), out collectionDefinition))
|
||||
{
|
||||
Type collectionItemType = ReflectionUtils.GetCollectionItemType(collectionDefinition);
|
||||
|
||||
@@ -398,7 +398,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(list, "list");
|
||||
|
||||
Type listDefinition;
|
||||
if (ReflectionUtils.ImplementsGenericInterfaceDefinition(list.GetType(), typeof(IList<>), out listDefinition))
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(list.GetType(), typeof(IList<>), out listDefinition))
|
||||
{
|
||||
Type collectionItemType = ReflectionUtils.GetCollectionItemType(listDefinition);
|
||||
|
||||
@@ -426,7 +426,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(dictionary, "dictionary");
|
||||
|
||||
Type dictionaryDefinition;
|
||||
if (ReflectionUtils.ImplementsGenericInterfaceDefinition(dictionary.GetType(), typeof(IDictionary<,>), out dictionaryDefinition))
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(dictionary.GetType(), typeof(IDictionary<,>), out dictionaryDefinition))
|
||||
{
|
||||
Type dictionaryKeyType = ReflectionUtils.GetDictionaryKeyType(dictionaryDefinition);
|
||||
Type dictionaryValueType = ReflectionUtils.GetDictionaryValueType(dictionaryDefinition);
|
||||
@@ -466,7 +466,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
list = new List<object>();
|
||||
isReadOnlyOrFixedSize = true;
|
||||
}
|
||||
else if (ReflectionUtils.InheritsGenericClassDefinition(listType, typeof(ReadOnlyCollection<>), out collectionType))
|
||||
else if (ReflectionUtils.InheritsGenericDefinition(listType, typeof(ReadOnlyCollection<>), out collectionType))
|
||||
{
|
||||
Type readOnlyCollectionContentsType = collectionType.GetGenericArguments()[0];
|
||||
Type genericEnumerable = ReflectionUtils.MakeGenericType(typeof(IEnumerable<>), readOnlyCollectionContentsType);
|
||||
@@ -522,7 +522,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
if (listType.IsArray)
|
||||
list = ToArray(((List<object>)list).ToArray(), ReflectionUtils.GetCollectionItemType(listType));
|
||||
else if (ReflectionUtils.InheritsGenericClassDefinition(listType, typeof(ReadOnlyCollection<>)))
|
||||
else if (ReflectionUtils.InheritsGenericDefinition(listType, typeof(ReadOnlyCollection<>)))
|
||||
list = (IList)ReflectionUtils.CreateInstance(listType, list);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,13 +124,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
return !CollectionUtils.IsNullOrEmpty<ParameterInfo>(property.GetIndexParameters());
|
||||
}
|
||||
|
||||
public static bool ImplementsGenericInterfaceDefinition(Type type, Type genericInterfaceDefinition)
|
||||
public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition)
|
||||
{
|
||||
Type implementingType;
|
||||
return ImplementsGenericInterfaceDefinition(type, genericInterfaceDefinition, out implementingType);
|
||||
return ImplementsGenericDefinition(type, genericInterfaceDefinition, out implementingType);
|
||||
}
|
||||
|
||||
public static bool ImplementsGenericInterfaceDefinition(Type type, Type genericInterfaceDefinition, out Type implementingType)
|
||||
public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition, out Type implementingType)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
ValidationUtils.ArgumentNotNull(genericInterfaceDefinition, "genericInterfaceDefinition");
|
||||
@@ -171,13 +171,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
|
||||
|
||||
public static bool InheritsGenericClassDefinition(Type type, Type genericClassDefinition)
|
||||
public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition)
|
||||
{
|
||||
Type implementingType;
|
||||
return InheritsGenericClassDefinition(type, genericClassDefinition, out implementingType);
|
||||
return InheritsGenericDefinition(type, genericClassDefinition, out implementingType);
|
||||
}
|
||||
|
||||
public static bool InheritsGenericClassDefinition(Type type, Type genericClassDefinition, out Type implementingType)
|
||||
public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition, out Type implementingType)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
ValidationUtils.ArgumentNotNull(genericClassDefinition, "genericClassDefinition");
|
||||
@@ -185,10 +185,10 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (!genericClassDefinition.IsClass || !genericClassDefinition.IsGenericTypeDefinition)
|
||||
throw new ArgumentNullException("'{0}' is not a generic class definition.".FormatWith(CultureInfo.InvariantCulture, genericClassDefinition));
|
||||
|
||||
return InheritsGenericClassDefinitionInternal(type, type, genericClassDefinition, out implementingType);
|
||||
return InheritsGenericDefinitionInternal(type, type, genericClassDefinition, out implementingType);
|
||||
}
|
||||
|
||||
private static bool InheritsGenericClassDefinitionInternal(Type initialType, Type currentType, Type genericClassDefinition, out Type implementingType)
|
||||
private static bool InheritsGenericDefinitionInternal(Type initialType, Type currentType, Type genericClassDefinition, out Type implementingType)
|
||||
{
|
||||
if (currentType.IsGenericType)
|
||||
{
|
||||
@@ -207,7 +207,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return false;
|
||||
}
|
||||
|
||||
return InheritsGenericClassDefinitionInternal(initialType, currentType.BaseType, genericClassDefinition, out implementingType);
|
||||
return InheritsGenericDefinitionInternal(initialType, currentType.BaseType, genericClassDefinition, out implementingType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -224,7 +224,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
return type.GetElementType();
|
||||
}
|
||||
else if (ImplementsGenericInterfaceDefinition(type, typeof(ICollection<>), out genericListType))
|
||||
else if (ImplementsGenericDefinition(type, typeof(ICollection<>), out genericListType))
|
||||
{
|
||||
if (genericListType.IsGenericTypeDefinition)
|
||||
throw new Exception("Type {0} is not a collection.".FormatWith(CultureInfo.InvariantCulture, type));
|
||||
@@ -246,7 +246,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(dictionaryType, "type");
|
||||
|
||||
Type genericDictionaryType;
|
||||
if (ImplementsGenericInterfaceDefinition(dictionaryType, typeof(IDictionary<,>), out genericDictionaryType))
|
||||
if (ImplementsGenericDefinition(dictionaryType, typeof(IDictionary<,>), out genericDictionaryType))
|
||||
{
|
||||
if (genericDictionaryType.IsGenericTypeDefinition)
|
||||
throw new Exception("Type {0} is not a dictionary.".FormatWith(CultureInfo.InvariantCulture, dictionaryType));
|
||||
|
||||
Reference in New Issue
Block a user