-Minor fixes
This commit is contained in:
@@ -503,7 +503,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < interations; i++)
|
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;
|
char[] buffer = null;
|
||||||
JavaScriptUtils.WriteEscapedJavaScriptString(w, text, '"', true, JavaScriptUtils.DoubleQuoteCharEscapeFlags, StringEscapeHandling.Default, null, ref buffer);
|
JavaScriptUtils.WriteEscapedJavaScriptString(w, text, '"', true, JavaScriptUtils.DoubleQuoteCharEscapeFlags, StringEscapeHandling.Default, null, ref buffer);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Converters
|
|||||||
public string DateTimeFormat
|
public string DateTimeFormat
|
||||||
{
|
{
|
||||||
get { return _dateTimeFormat ?? string.Empty; }
|
get { return _dateTimeFormat ?? string.Empty; }
|
||||||
set { _dateTimeFormat = StringUtils.NullEmptyString(value); }
|
set { _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -70,23 +70,23 @@ namespace Newtonsoft.Json
|
|||||||
public object[] ItemConverterParameters { get; set; }
|
public object[] ItemConverterParameters { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="Type"/> of the <see cref="Serialization.NamingStrategy"/>.
|
/// Gets the <see cref="Type"/> of the <see cref="NamingStrategy"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The <see cref="Type"/> of the <see cref="Serialization.NamingStrategy"/>.</value>
|
/// <value>The <see cref="Type"/> of the <see cref="NamingStrategy"/>.</value>
|
||||||
public Type NamingStrategyType
|
public Type NamingStrategyType
|
||||||
{
|
{
|
||||||
get { return _namingStrategyType; }
|
get { return _namingStrategyType; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_namingStrategyType = value;
|
_namingStrategyType = value;
|
||||||
NamingStrategy = null;
|
NamingStrategyInstance = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The parameter list to use when constructing the <see cref="Serialization.NamingStrategy"/> described by NamingStrategyType.
|
/// The parameter list to use when constructing the <see cref="NamingStrategy"/> described by NamingStrategyType.
|
||||||
/// If null, the default constructor is used.
|
/// If null, the default constructor is used.
|
||||||
/// When non-null, there must be a constructor defined in the <see cref="Serialization.NamingStrategy"/> that exactly matches the number,
|
/// When non-null, there must be a constructor defined in the <see cref="NamingStrategy"/> that exactly matches the number,
|
||||||
/// order, and type of these parameters.
|
/// order, and type of these parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>
|
/// <example>
|
||||||
@@ -98,11 +98,11 @@ namespace Newtonsoft.Json
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_namingStrategyParameters = value;
|
_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#
|
// yuck. can't set nullable properties on an attribute in C#
|
||||||
// have to use this approach to get an unset default state
|
// have to use this approach to get an unset default state
|
||||||
|
|||||||
@@ -192,18 +192,17 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public static NamingStrategy GetContainerNamingStrategy(JsonContainerAttribute containerAttribute)
|
public static NamingStrategy GetContainerNamingStrategy(JsonContainerAttribute containerAttribute)
|
||||||
{
|
{
|
||||||
if (containerAttribute.NamingStrategy == null)
|
if (containerAttribute.NamingStrategyInstance == null)
|
||||||
{
|
{
|
||||||
if (containerAttribute.NamingStrategyType == null)
|
if (containerAttribute.NamingStrategyType == null)
|
||||||
{
|
{
|
||||||
return 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<object[], object> GetCreator(Type type)
|
private static Func<object[], object> GetCreator(Type type)
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
{
|
{
|
||||||
bool[] charEscapeFlags = GetCharEscapeFlags(stringEscapeHandling, delimiter);
|
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;
|
char[] buffer = null;
|
||||||
WriteEscapedJavaScriptString(w, value, delimiter, appendDelimiters, charEscapeFlags, stringEscapeHandling, null, ref buffer);
|
WriteEscapedJavaScriptString(w, value, delimiter, appendDelimiters, charEscapeFlags, stringEscapeHandling, null, ref buffer);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ using Newtonsoft.Json.Utilities.LinqBridge;
|
|||||||
#else
|
#else
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#endif
|
#endif
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Utilities
|
namespace Newtonsoft.Json.Utilities
|
||||||
{
|
{
|
||||||
@@ -104,16 +103,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Nulls an empty string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="s">The string.</param>
|
|
||||||
/// <returns>Null if the string was null, otherwise the string unchanged.</returns>
|
|
||||||
public static string NullEmptyString(string s)
|
|
||||||
{
|
|
||||||
return (string.IsNullOrEmpty(s)) ? null : s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StringWriter CreateStringWriter(int capacity)
|
public static StringWriter CreateStringWriter(int capacity)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder(capacity);
|
StringBuilder sb = new StringBuilder(capacity);
|
||||||
@@ -122,18 +111,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
return sw;
|
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)
|
public static void ToCharAsUnicode(char c, char[] buffer)
|
||||||
{
|
{
|
||||||
buffer[0] = '\\';
|
buffer[0] = '\\';
|
||||||
@@ -233,17 +210,17 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case SnakeCaseState.Upper:
|
case SnakeCaseState.Upper:
|
||||||
bool hasNext = (i + 1 < s.Length);
|
bool hasNext = (i + 1 < s.Length);
|
||||||
if (i > 0 && hasNext && !char.IsUpper(s[i + 1]))
|
if (i > 0 && hasNext && !char.IsUpper(s[i + 1]))
|
||||||
{
|
{
|
||||||
|
sb.Append('_');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SnakeCaseState.Lower:
|
||||||
|
case SnakeCaseState.NewWord:
|
||||||
sb.Append('_');
|
sb.Append('_');
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
case SnakeCaseState.Lower:
|
|
||||||
case SnakeCaseState.NewWord:
|
|
||||||
sb.Append('_');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|||||||
Reference in New Issue
Block a user