-Formatting
-Build
This commit is contained in:
@@ -100,11 +100,15 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
MethodInfo m = propertyInfo.GetGetMethod();
|
||||
if (m != null && m.IsVirtual)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
m = propertyInfo.GetSetMethod();
|
||||
if (m != null && m.IsVirtual)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -115,11 +119,15 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
MethodInfo m = propertyInfo.GetGetMethod();
|
||||
if (m != null)
|
||||
{
|
||||
return m.GetBaseDefinition();
|
||||
}
|
||||
|
||||
m = propertyInfo.GetSetMethod();
|
||||
if (m != null)
|
||||
{
|
||||
return m.GetBaseDefinition();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -127,9 +135,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
public static bool IsPublic(PropertyInfo property)
|
||||
{
|
||||
if (property.GetGetMethod() != null && property.GetGetMethod().IsPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (property.GetSetMethod() != null && property.GetSetMethod().IsPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -203,7 +215,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
break;
|
||||
default:
|
||||
if (!skippingAssemblyDetails)
|
||||
{
|
||||
builder.Append(current);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +230,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(t, "t");
|
||||
|
||||
if (t.IsValueType())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return (GetDefaultConstructor(t, nonPublic) != null);
|
||||
}
|
||||
@@ -230,7 +246,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;
|
||||
if (nonPublic)
|
||||
{
|
||||
bindingFlags = bindingFlags | BindingFlags.NonPublic;
|
||||
}
|
||||
|
||||
return t.GetConstructors(bindingFlags).SingleOrDefault(c => !c.GetParameters().Any());
|
||||
}
|
||||
@@ -240,7 +258,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(t, "t");
|
||||
|
||||
if (t.IsValueType())
|
||||
{
|
||||
return IsNullableType(t);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -262,7 +282,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
public static bool IsGenericDefinition(Type type, Type genericInterfaceDefinition)
|
||||
{
|
||||
if (!type.IsGenericType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Type t = type.GetGenericTypeDefinition();
|
||||
return (t == genericInterfaceDefinition);
|
||||
@@ -280,7 +302,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(genericInterfaceDefinition, "genericInterfaceDefinition");
|
||||
|
||||
if (!genericInterfaceDefinition.IsInterface() || !genericInterfaceDefinition.IsGenericTypeDefinition())
|
||||
{
|
||||
throw new ArgumentNullException("'{0}' is not a generic interface definition.".FormatWith(CultureInfo.InvariantCulture, genericInterfaceDefinition));
|
||||
}
|
||||
|
||||
if (type.IsInterface())
|
||||
{
|
||||
@@ -326,7 +350,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
ValidationUtils.ArgumentNotNull(genericClassDefinition, "genericClassDefinition");
|
||||
|
||||
if (!genericClassDefinition.IsClass() || !genericClassDefinition.IsGenericTypeDefinition())
|
||||
{
|
||||
throw new ArgumentNullException("'{0}' is not a generic class definition.".FormatWith(CultureInfo.InvariantCulture, genericClassDefinition));
|
||||
}
|
||||
|
||||
return InheritsGenericDefinitionInternal(type, genericClassDefinition, out implementingType);
|
||||
}
|
||||
@@ -370,7 +396,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (ImplementsGenericDefinition(type, typeof(IEnumerable<>), out genericListType))
|
||||
{
|
||||
if (genericListType.IsGenericTypeDefinition())
|
||||
{
|
||||
throw new Exception("Type {0} is not a collection.".FormatWith(CultureInfo.InvariantCulture, type));
|
||||
}
|
||||
|
||||
return genericListType.GetGenericArguments()[0];
|
||||
}
|
||||
@@ -378,7 +406,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
throw new Exception("Type {0} is not a collection.".FormatWith(CultureInfo.InvariantCulture, type));
|
||||
}
|
||||
|
||||
@@ -390,7 +418,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (ImplementsGenericDefinition(dictionaryType, typeof(IDictionary<,>), out genericDictionaryType))
|
||||
{
|
||||
if (genericDictionaryType.IsGenericTypeDefinition())
|
||||
{
|
||||
throw new Exception("Type {0} is not a dictionary.".FormatWith(CultureInfo.InvariantCulture, dictionaryType));
|
||||
}
|
||||
|
||||
Type[] dictionaryGenericArguments = genericDictionaryType.GetGenericArguments();
|
||||
|
||||
@@ -446,9 +476,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
PropertyInfo propertyInfo = member as PropertyInfo;
|
||||
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
return IsIndexedProperty(propertyInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -534,17 +568,25 @@ namespace Newtonsoft.Json.Utilities
|
||||
FieldInfo fieldInfo = (FieldInfo)member;
|
||||
|
||||
if (nonPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (fieldInfo.IsPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MemberTypes.Property:
|
||||
PropertyInfo propertyInfo = (PropertyInfo)member;
|
||||
|
||||
if (!propertyInfo.CanRead)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (nonPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return (propertyInfo.GetGetMethod(nonPublic) != null);
|
||||
default:
|
||||
return false;
|
||||
@@ -568,21 +610,33 @@ namespace Newtonsoft.Json.Utilities
|
||||
FieldInfo fieldInfo = (FieldInfo)member;
|
||||
|
||||
if (fieldInfo.IsLiteral)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (fieldInfo.IsInitOnly && !canSetReadOnly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (nonPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (fieldInfo.IsPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MemberTypes.Property:
|
||||
PropertyInfo propertyInfo = (PropertyInfo)member;
|
||||
|
||||
if (!propertyInfo.CanWrite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (nonPublic)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return (propertyInfo.GetSetMethod(nonPublic) != null);
|
||||
default:
|
||||
return false;
|
||||
@@ -620,9 +674,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
// if the hiding property is hiding a base property and it is virtual
|
||||
// then this ensures the derived property gets used
|
||||
if (resolvedMembers.Count == 0)
|
||||
{
|
||||
resolvedMembers.Add(memberInfo);
|
||||
}
|
||||
else if (!IsOverridenGenericMember(memberInfo, bindingAttr) || memberInfo.Name == "Item")
|
||||
{
|
||||
resolvedMembers.Add(memberInfo);
|
||||
}
|
||||
}
|
||||
|
||||
distinctMembers.AddRange(resolvedMembers);
|
||||
@@ -635,24 +693,36 @@ namespace Newtonsoft.Json.Utilities
|
||||
private static bool IsOverridenGenericMember(MemberInfo memberInfo, BindingFlags bindingAttr)
|
||||
{
|
||||
if (memberInfo.MemberType() != MemberTypes.Property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
|
||||
if (!IsVirtual(propertyInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Type declaringType = propertyInfo.DeclaringType;
|
||||
if (!declaringType.IsGenericType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Type genericTypeDefinition = declaringType.GetGenericTypeDefinition();
|
||||
if (genericTypeDefinition == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
MemberInfo[] members = genericTypeDefinition.GetMember(propertyInfo.Name, bindingAttr);
|
||||
if (members.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Type memberUnderlyingType = GetMemberUnderlyingType(members[0]);
|
||||
if (!memberUnderlyingType.IsGenericParameter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -676,7 +746,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
T[] attributes = a as T[];
|
||||
if (attributes != null)
|
||||
{
|
||||
return attributes;
|
||||
}
|
||||
|
||||
return a.Cast<T>().ToArray();
|
||||
}
|
||||
@@ -697,7 +769,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
Attribute[] attributes = a.Cast<Attribute>().ToArray();
|
||||
|
||||
#if (NET20 || NET35)
|
||||
// ye olde .NET GetCustomAttributes doesn't respect the inherit argument
|
||||
// ye olde .NET GetCustomAttributes doesn't respect the inherit argument
|
||||
if (inherit && t.BaseType != null)
|
||||
attributes = attributes.Union(GetAttributes(t.BaseType, attributeType, inherit)).ToArray();
|
||||
#endif
|
||||
@@ -818,7 +890,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
break;
|
||||
case ',':
|
||||
if (scope == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -960,7 +1034,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
&& p.DeclaringType == subTypeProperty.DeclaringType);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
initialProperties.Add(subTypeProperty);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -970,7 +1046,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
&& p.GetBaseDefinition().DeclaringType.IsAssignableFrom(subTypeProperty.GetBaseDefinition().DeclaringType));
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
initialProperties.Add(subTypeProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -993,7 +1071,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
public static object GetDefaultValue(Type type)
|
||||
{
|
||||
if (!type.IsValueType())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (ConvertUtils.GetTypeCode(type))
|
||||
{
|
||||
@@ -1031,7 +1111,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
|
||||
if (IsNullable(type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// possibly use IL initobj for perf here?
|
||||
return Activator.CreateInstance(type);
|
||||
|
||||
Reference in New Issue
Block a user