diff --git a/Src/Newtonsoft.Json/JsonPosition.cs b/Src/Newtonsoft.Json/JsonPosition.cs index 1e2f0628..02263d7f 100644 --- a/Src/Newtonsoft.Json/JsonPosition.cs +++ b/Src/Newtonsoft.Json/JsonPosition.cs @@ -92,7 +92,7 @@ namespace Newtonsoft.Json internal static string FormatMessage(IJsonLineInfo lineInfo, string path, string message) { // don't add a fullstop and space when message ends with a new line - if (!message.EndsWith(Environment.NewLine)) + if (!message.EndsWith(Environment.NewLine, StringComparison.Ordinal)) { message = message.Trim(); diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index d646339c..57975f1a 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -783,7 +783,7 @@ namespace Newtonsoft.Json if (Value.ToString() == JsonTypeReflector.TypePropertyName) { ReadInternal(); - if (Value != null && Value.ToString().StartsWith("System.Byte[]")) + if (Value != null && Value.ToString().StartsWith("System.Byte[]", StringComparison.Ordinal)) { ReadInternal(); if (Value.ToString() == JsonTypeReflector.ValuePropertyName) diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index a39ed0c3..aa98c3b5 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -57,7 +57,6 @@ namespace Newtonsoft.Json public string CurrentPropertyName { get; set; } public int ArrayItemCount { get; set; } public bool IsUniqueArray { get; set; } - public bool IsEnum { get; set; } public IList UniqueArrayItems { get; set; } public JTokenWriter CurrentItemWriter { get; set; } @@ -575,7 +574,7 @@ namespace Newtonsoft.Json { bool isInUniqueArray = (schemaScope.TokenType == JTokenType.Array && schemaScope.IsUniqueArray && schemaScope.ArrayItemCount > 0); - if (isInUniqueArray || schemaScope.IsEnum || schemas.Any(s => s.Enum != null)) + if (isInUniqueArray || schemas.Any(s => s.Enum != null)) { if (schemaScope.CurrentItemWriter == null) { @@ -602,7 +601,7 @@ namespace Newtonsoft.Json schemaScope.UniqueArrayItems.Add(finishedItem); } - else if (schemaScope.IsEnum || schemas.Any(s => s.Enum != null)) + else if (schemas.Any(s => s.Enum != null)) { foreach (JsonSchemaModel schema in schemas) { diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.ruleset b/Src/Newtonsoft.Json/Newtonsoft.Json.ruleset index ff6201db..17596c23 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.ruleset +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.ruleset @@ -1,236 +1,15 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 245a295c..c05839d0 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -673,7 +673,7 @@ namespace Newtonsoft.Json.Serialization /// The contract's default . protected virtual JsonConverter ResolveContractConverter(Type objectType) { - return JsonTypeReflector.GetJsonConverter(objectType, objectType); + return JsonTypeReflector.GetJsonConverter(objectType); } private Func GetDefaultCreator(Type createdType) @@ -1252,8 +1252,8 @@ namespace Newtonsoft.Json.Serialization // resolve converter for property // the class type might have a converter but the property converter takes presidence - property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); - property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); + property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider); + property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute(attributeProvider); if (defaultValueAttribute != null) diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index a205efe5..325ca4d9 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -57,7 +57,6 @@ namespace Newtonsoft.Json.Serialization /// true if the collection type is a multidimensional array; otherwise, false. public bool IsMultidimensionalArray { get; private set; } - private readonly bool _isCollectionItemTypeNullableType; private readonly Type _genericCollectionDefinitionType; private Type _genericWrapperType; @@ -182,17 +181,16 @@ namespace Newtonsoft.Json.Serialization CanDeserialize = canDeserialize; - if (CollectionItemType != null) - _isCollectionItemTypeNullableType = ReflectionUtils.IsNullableType(CollectionItemType); - #if (NET20 || NET35) - // bug in .NET 2.0 & 3.5 that List> throws an error when adding null via IList.Add(object) - // wrapper will handle calling Add(T) instead - if (_isCollectionItemTypeNullableType - && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(List<>), out tempCollectionType) - || (IsArray && !IsMultidimensionalArray))) + if (CollectionItemType != null && ReflectionUtils.IsNullableType(CollectionItemType)) { - ShouldCreateWrapper = true; + // bug in .NET 2.0 & 3.5 that List> throws an error when adding null via IList.Add(object) + // wrapper will handle calling Add(T) instead + if (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(List<>), out tempCollectionType) + || (IsArray && !IsMultidimensionalArray)) + { + ShouldCreateWrapper = true; + } } #endif diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index 48bae167..a6b7d539 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -61,7 +61,6 @@ namespace Newtonsoft.Json.Serialization internal JsonContract KeyContract { get; set; } - private readonly bool _isDictionaryValueTypeNullableType; private readonly Type _genericCollectionDefinitionType; private Type _genericWrapperType; @@ -134,18 +133,17 @@ namespace Newtonsoft.Json.Serialization DictionaryKeyType = keyType; DictionaryValueType = valueType; - if (DictionaryValueType != null) - _isDictionaryValueTypeNullableType = ReflectionUtils.IsNullableType(DictionaryValueType); - #if (NET20 || NET35) - Type tempDictioanryType; - - // bug in .NET 2.0 & 3.5 that Dictionary> throws an error when adding null via IDictionary[key] = object - // wrapper will handle calling Add(T) instead - if (_isDictionaryValueTypeNullableType - && (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(Dictionary<,>), out tempDictioanryType))) + if (DictionaryValueType != null && ReflectionUtils.IsNullableType(DictionaryValueType)) { - ShouldCreateWrapper = true; + Type tempDictioanryType; + + // bug in .NET 2.0 & 3.5 that Dictionary> throws an error when adding null via IDictionary[key] = object + // wrapper will handle calling Add(T) instead + if (ReflectionUtils.InheritsGenericDefinition(CreatedType, typeof(Dictionary<,>), out tempDictioanryType)) + { + ShouldCreateWrapper = true; + } } #endif diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index d50e0908..7135e6b3 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -187,7 +187,7 @@ namespace Newtonsoft.Json.Serialization : null; } - public static JsonConverter GetJsonConverter(object attributeProvider, Type targetConvertedType) + public static JsonConverter GetJsonConverter(object attributeProvider) { Type converterType = GetJsonConverterType(attributeProvider); diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeParser.cs b/Src/Newtonsoft.Json/Utilities/DateTimeParser.cs index d09ff097..3188d560 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeParser.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeParser.cs @@ -54,8 +54,6 @@ namespace Newtonsoft.Json.Utilities LzHH_mm_ss = "HH:mm:ss".Length; Lz_ = "-".Length; Lz_zz = "-zz".Length; - Lz_zz_ = "-zz:".Length; - Lz_zz_zz = "-zz:zz".Length; } public int Year; @@ -87,8 +85,6 @@ namespace Newtonsoft.Json.Utilities private static readonly int LzHH_mm_ss; private static readonly int Lz_; private static readonly int Lz_zz; - private static readonly int Lz_zz_; - private static readonly int Lz_zz_zz; private const short MaxFractionDigits = 7; diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index a585cc7f..dc824185 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -698,8 +698,9 @@ namespace Newtonsoft.Json.Utilities #if !PORTABLE40 return (T[])((ICustomAttributeProvider)attributeProvider).GetCustomAttributes(typeof(T), inherit); -#endif +#else throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider)); +#endif } #else public static T[] GetAttributes(object provider, bool inherit) where T : Attribute