diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 7fdd7ec7..475cc910 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -503,7 +503,7 @@ If attributes are not mentioned, default values are used in each case. { for (int i = 0; i < interations; i++) { - using (StringWriter w = StringUtils.CreateStringWriter(StringUtils.GetLength(text) ?? 16)) + using (StringWriter w = StringUtils.CreateStringWriter(text.Length)) { char[] buffer = null; JavaScriptUtils.WriteEscapedJavaScriptString(w, text, '"', true, JavaScriptUtils.DoubleQuoteCharEscapeFlags, StringEscapeHandling.Default, null, ref buffer); diff --git a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs index 9d2f822a..ceb38797 100644 --- a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs @@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Converters public string DateTimeFormat { get { return _dateTimeFormat ?? string.Empty; } - set { _dateTimeFormat = StringUtils.NullEmptyString(value); } + set { _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; } } /// diff --git a/Src/Newtonsoft.Json/JsonContainerAttribute.cs b/Src/Newtonsoft.Json/JsonContainerAttribute.cs index 72d19424..1deab53a 100644 --- a/Src/Newtonsoft.Json/JsonContainerAttribute.cs +++ b/Src/Newtonsoft.Json/JsonContainerAttribute.cs @@ -70,23 +70,23 @@ namespace Newtonsoft.Json public object[] ItemConverterParameters { get; set; } /// - /// Gets the of the . + /// Gets the of the . /// - /// The of the . + /// The of the . public Type NamingStrategyType { get { return _namingStrategyType; } set { _namingStrategyType = value; - NamingStrategy = null; + NamingStrategyInstance = null; } } /// - /// The parameter list to use when constructing the described by NamingStrategyType. + /// The parameter list to use when constructing the described by NamingStrategyType. /// If null, the default constructor is used. - /// When non-null, there must be a constructor defined in the that exactly matches the number, + /// When non-null, there must be a constructor defined in the that exactly matches the number, /// order, and type of these parameters. /// /// @@ -98,11 +98,11 @@ namespace Newtonsoft.Json set { _namingStrategyParameters = value; - NamingStrategy = null; + NamingStrategyInstance = null; } } - internal NamingStrategy NamingStrategy { get; set; } + internal NamingStrategy NamingStrategyInstance { get; set; } // yuck. can't set nullable properties on an attribute in C# // have to use this approach to get an unset default state diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index 78cee84c..ae1b5349 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -192,18 +192,17 @@ namespace Newtonsoft.Json.Serialization public static NamingStrategy GetContainerNamingStrategy(JsonContainerAttribute containerAttribute) { - if (containerAttribute.NamingStrategy == null) + if (containerAttribute.NamingStrategyInstance == null) { if (containerAttribute.NamingStrategyType == null) { return null; - } - containerAttribute.NamingStrategy = CreateNamingStrategyInstance(containerAttribute.NamingStrategyType, containerAttribute.NamingStrategyParameters); + containerAttribute.NamingStrategyInstance = CreateNamingStrategyInstance(containerAttribute.NamingStrategyType, containerAttribute.NamingStrategyParameters); } - return containerAttribute.NamingStrategy; + return containerAttribute.NamingStrategyInstance; } private static Func GetCreator(Type type) diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index e8ef53e7..887d9773 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -307,7 +307,7 @@ namespace Newtonsoft.Json.Utilities { bool[] charEscapeFlags = GetCharEscapeFlags(stringEscapeHandling, delimiter); - using (StringWriter w = StringUtils.CreateStringWriter(StringUtils.GetLength(value) ?? 16)) + using (StringWriter w = StringUtils.CreateStringWriter(value?.Length ?? 16)) { char[] buffer = null; WriteEscapedJavaScriptString(w, value, delimiter, appendDelimiters, charEscapeFlags, stringEscapeHandling, null, ref buffer); diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index fabf7c0e..54737636 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -33,7 +33,6 @@ using Newtonsoft.Json.Utilities.LinqBridge; #else using System.Linq; #endif -using Newtonsoft.Json.Serialization; namespace Newtonsoft.Json.Utilities { @@ -104,16 +103,6 @@ namespace Newtonsoft.Json.Utilities return true; } - /// - /// Nulls an empty string. - /// - /// The string. - /// Null if the string was null, otherwise the string unchanged. - public static string NullEmptyString(string s) - { - return (string.IsNullOrEmpty(s)) ? null : s; - } - public static StringWriter CreateStringWriter(int capacity) { StringBuilder sb = new StringBuilder(capacity); @@ -122,18 +111,6 @@ namespace Newtonsoft.Json.Utilities return sw; } - public static int? GetLength(string value) - { - if (value == null) - { - return null; - } - else - { - return value.Length; - } - } - public static void ToCharAsUnicode(char c, char[] buffer) { buffer[0] = '\\'; @@ -233,17 +210,17 @@ namespace Newtonsoft.Json.Utilities { switch (state) { - case SnakeCaseState.Upper: - bool hasNext = (i + 1 < s.Length); - if (i > 0 && hasNext && !char.IsUpper(s[i + 1])) - { + case SnakeCaseState.Upper: + bool hasNext = (i + 1 < s.Length); + if (i > 0 && hasNext && !char.IsUpper(s[i + 1])) + { + sb.Append('_'); + } + break; + case SnakeCaseState.Lower: + case SnakeCaseState.NewWord: sb.Append('_'); - } - break; - case SnakeCaseState.Lower: - case SnakeCaseState.NewWord: - sb.Append('_'); - break; + break; } char c;