-Formatting
This commit is contained in:
@@ -51,18 +51,18 @@ namespace Newtonsoft.Json.TestConsole
|
|||||||
//PerformanceTests t = new PerformanceTests();
|
//PerformanceTests t = new PerformanceTests();
|
||||||
//t.DeserializeLargeJson();
|
//t.DeserializeLargeJson();
|
||||||
|
|
||||||
PerformanceTests t = new PerformanceTests();
|
//PerformanceTests t = new PerformanceTests();
|
||||||
t.Iterations = 10000;
|
//t.Iterations = 50000;
|
||||||
t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText);
|
//t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText);
|
||||||
|
|
||||||
Console.WriteLine("Wait to do stuff again");
|
//Console.WriteLine("Wait to do stuff again");
|
||||||
Console.ReadKey();
|
//Console.ReadKey();
|
||||||
|
|
||||||
t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText);
|
//t.BenchmarkDeserializeMethod<TestClass>(PerformanceTests.SerializeMethod.JsonNet, PerformanceTests.JsonText);
|
||||||
|
|
||||||
//ReadLargeJson();
|
//ReadLargeJson();
|
||||||
//WriteLargeJson();
|
//WriteLargeJson();
|
||||||
//DeserializeJson();
|
DeserializeJson();
|
||||||
//ReadLargeJson();
|
//ReadLargeJson();
|
||||||
//ReadLargeJsonJavaScriptSerializer();
|
//ReadLargeJsonJavaScriptSerializer();
|
||||||
|
|
||||||
|
|||||||
@@ -463,36 +463,36 @@ namespace Newtonsoft.Json.Tests
|
|||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("How now brown cow?", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How now brown cow?", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""How now brown cow?""", result);
|
Assert.AreEqual(@"""How now brown cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("How now 'brown' cow?", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How now 'brown' cow?", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""How now 'brown' cow?""", result);
|
Assert.AreEqual(@"""How now 'brown' cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("How now <brown> cow?", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How now <brown> cow?", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""How now <brown> cow?""", result);
|
Assert.AreEqual(@"""How now <brown> cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("How \r\nnow brown cow?", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("How \r\nnow brown cow?", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""How \r\nnow brown cow?""", result);
|
Assert.AreEqual(@"""How \r\nnow brown cow?""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007""", result);
|
Assert.AreEqual(@"""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007""", result);
|
||||||
|
|
||||||
result =
|
result =
|
||||||
JavaScriptUtils.ToEscapedJavaScriptString("\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013", '"', true);
|
JavaScriptUtils.ToEscapedJavaScriptString("\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013""", result);
|
Assert.AreEqual(@"""\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013""", result);
|
||||||
|
|
||||||
result =
|
result =
|
||||||
JavaScriptUtils.ToEscapedJavaScriptString(
|
JavaScriptUtils.ToEscapedJavaScriptString(
|
||||||
"\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f ", '"', true);
|
"\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f ", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f """, result);
|
Assert.AreEqual(@"""\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f """, result);
|
||||||
|
|
||||||
result =
|
result =
|
||||||
JavaScriptUtils.ToEscapedJavaScriptString(
|
JavaScriptUtils.ToEscapedJavaScriptString(
|
||||||
"!\"#$%&\u0027()*+,-./0123456789:;\u003c=\u003e?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]", '"', true);
|
"!\"#$%&\u0027()*+,-./0123456789:;\u003c=\u003e?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""!\""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]""", result);
|
Assert.AreEqual(@"""!\""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("^_`abcdefghijklmnopqrstuvwxyz{|}~", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("^_`abcdefghijklmnopqrstuvwxyz{|}~", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""^_`abcdefghijklmnopqrstuvwxyz{|}~""", result);
|
Assert.AreEqual(@"""^_`abcdefghijklmnopqrstuvwxyz{|}~""", result);
|
||||||
|
|
||||||
string data =
|
string data =
|
||||||
@@ -500,22 +500,22 @@ namespace Newtonsoft.Json.Tests
|
|||||||
string expected =
|
string expected =
|
||||||
@"""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~""";
|
@"""\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~""";
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString(data, '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString(data, '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(expected, result);
|
Assert.AreEqual(expected, result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("Fred's cat.", '\'', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("Fred's cat.", '\'', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(result, @"'Fred\'s cat.'");
|
Assert.AreEqual(result, @"'Fred\'s cat.'");
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString(@"""How are you gentlemen?"" said Cats.", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString(@"""How are you gentlemen?"" said Cats.", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(result, @"""\""How are you gentlemen?\"" said Cats.""");
|
Assert.AreEqual(result, @"""\""How are you gentlemen?\"" said Cats.""");
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString(@"""How are' you gentlemen?"" said Cats.", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString(@"""How are' you gentlemen?"" said Cats.", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(result, @"""\""How are' you gentlemen?\"" said Cats.""");
|
Assert.AreEqual(result, @"""\""How are' you gentlemen?\"" said Cats.""");
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString(@"Fred's ""cat"".", '\'', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString(@"Fred's ""cat"".", '\'', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(result, @"'Fred\'s ""cat"".'");
|
Assert.AreEqual(result, @"'Fred\'s ""cat"".'");
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(result, @"""\u001farray<address""");
|
Assert.AreEqual(result, @"""\u001farray<address""");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,13 +524,13 @@ namespace Newtonsoft.Json.Tests
|
|||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u0085' + "after", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u0085' + "after", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""before\u0085after""", result);
|
Assert.AreEqual(@"""before\u0085after""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u2028' + "after", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u2028' + "after", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""before\u2028after""", result);
|
Assert.AreEqual(@"""before\u2028after""", result);
|
||||||
|
|
||||||
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u2029' + "after", '"', true);
|
result = JavaScriptUtils.ToEscapedJavaScriptString("before" + '\u2029' + "after", '"', true, StringEscapeHandling.Default);
|
||||||
Assert.AreEqual(@"""before\u2029after""", result);
|
Assert.AreEqual(@"""before\u2029after""", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2785,6 +2785,13 @@ new Date()"));
|
|||||||
Assert.AreEqual(12.34d, reader.ReadAsDouble());
|
Assert.AreEqual(12.34d, reader.ReadAsDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReadAsDouble_AllowThousands()
|
||||||
|
{
|
||||||
|
JsonTextReader reader = new JsonTextReader(new StringReader("'1,112.34'"));
|
||||||
|
Assert.AreEqual(1112.34d, reader.ReadAsDouble());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ReadAsDouble_Failure()
|
public void ReadAsDouble_Failure()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -849,7 +849,7 @@ If attributes are not mentioned, default values are used in each case.
|
|||||||
|
|
||||||
using (JsonTextReader reader = new JsonTextReader(new StringReader(json)))
|
using (JsonTextReader reader = new JsonTextReader(new StringReader(json)))
|
||||||
{
|
{
|
||||||
reader.ArrayPool = JsonArrayPool.Instance;
|
//reader.ArrayPool = JsonArrayPool.Instance;
|
||||||
|
|
||||||
var value = (T)serializer.Deserialize(reader, type);
|
var value = (T)serializer.Deserialize(reader, type);
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="value">The Oid value.</param>
|
/// <param name="value">The Oid value.</param>
|
||||||
public BsonObjectId(byte[] value)
|
public BsonObjectId(byte[] value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
if (value.Length != 12)
|
if (value.Length != 12)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("An ObjectId must be 12 bytes", nameof(value));
|
throw new ArgumentException("An ObjectId must be 12 bytes", nameof(value));
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="dateTimeKindHandling">The <see cref="DateTimeKind" /> used when reading <see cref="DateTime"/> values from BSON.</param>
|
/// <param name="dateTimeKindHandling">The <see cref="DateTimeKind" /> used when reading <see cref="DateTime"/> values from BSON.</param>
|
||||||
public BsonReader(Stream stream, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
|
public BsonReader(Stream stream, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(stream, "stream");
|
ValidationUtils.ArgumentNotNull(stream, nameof(stream));
|
||||||
_reader = new BinaryReader(stream);
|
_reader = new BinaryReader(stream);
|
||||||
_stack = new List<ContainerContext>();
|
_stack = new List<ContainerContext>();
|
||||||
_readRootValueAsArray = readRootValueAsArray;
|
_readRootValueAsArray = readRootValueAsArray;
|
||||||
@@ -160,7 +160,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="dateTimeKindHandling">The <see cref="DateTimeKind" /> used when reading <see cref="DateTime"/> values from BSON.</param>
|
/// <param name="dateTimeKindHandling">The <see cref="DateTimeKind" /> used when reading <see cref="DateTime"/> values from BSON.</param>
|
||||||
public BsonReader(BinaryReader reader, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
|
public BsonReader(BinaryReader reader, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
_stack = new List<ContainerContext>();
|
_stack = new List<ContainerContext>();
|
||||||
_readRootValueAsArray = readRootValueAsArray;
|
_readRootValueAsArray = readRootValueAsArray;
|
||||||
@@ -586,7 +586,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
int totalBytesRead = 0;
|
int totalBytesRead = 0;
|
||||||
// used in case of left over multibyte characters in the buffer
|
// used in case of left over multibyte characters in the buffer
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
int count = offset;
|
int count = offset;
|
||||||
byte b;
|
byte b;
|
||||||
@@ -638,7 +638,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ReadLengthString()
|
private string ReadLengthString()
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="stream">The stream.</param>
|
/// <param name="stream">The stream.</param>
|
||||||
public BsonWriter(Stream stream)
|
public BsonWriter(Stream stream)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(stream, "stream");
|
ValidationUtils.ArgumentNotNull(stream, nameof(stream));
|
||||||
_writer = new BsonBinaryWriter(new BinaryWriter(stream));
|
_writer = new BsonBinaryWriter(new BinaryWriter(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="writer">The writer.</param>
|
/// <param name="writer">The writer.</param>
|
||||||
public BsonWriter(BinaryWriter writer)
|
public BsonWriter(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(writer, "writer");
|
ValidationUtils.ArgumentNotNull(writer, nameof(writer));
|
||||||
_writer = new BsonBinaryWriter(writer);
|
_writer = new BsonBinaryWriter(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="value">The Object ID value to write.</param>
|
/// <param name="value">The Object ID value to write.</param>
|
||||||
public void WriteObjectId(byte[] value)
|
public void WriteObjectId(byte[] value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
if (value.Length != 12)
|
if (value.Length != 12)
|
||||||
{
|
{
|
||||||
@@ -520,7 +520,7 @@ namespace Newtonsoft.Json.Bson
|
|||||||
/// <param name="options">The regex options.</param>
|
/// <param name="options">The regex options.</param>
|
||||||
public void WriteRegex(string pattern, string options)
|
public void WriteRegex(string pattern, string options)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(pattern, "pattern");
|
ValidationUtils.ArgumentNotNull(pattern, nameof(pattern));
|
||||||
|
|
||||||
// hack to update the writer state
|
// hack to update the writer state
|
||||||
UpdateScopeWithFinishedValue();
|
UpdateScopeWithFinishedValue();
|
||||||
|
|||||||
@@ -848,7 +848,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <returns>The deserialized object from the JSON string.</returns>
|
/// <returns>The deserialized object from the JSON string.</returns>
|
||||||
public static object DeserializeObject(string value, Type type, JsonSerializerSettings settings)
|
public static object DeserializeObject(string value, Type type, JsonSerializerSettings settings)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
|
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
|
||||||
|
|
||||||
|
|||||||
@@ -414,7 +414,9 @@ namespace Newtonsoft.Json
|
|||||||
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
/// <returns>A <see cref="Nullable{Int32}"/>. This method will return <c>null</c> at the end of an array.</returns>
|
||||||
public virtual int? ReadAsInt32()
|
public virtual int? ReadAsInt32()
|
||||||
{
|
{
|
||||||
switch (GetContentToken())
|
JsonToken t = GetContentToken();
|
||||||
|
|
||||||
|
switch (t)
|
||||||
{
|
{
|
||||||
case JsonToken.None:
|
case JsonToken.None:
|
||||||
case JsonToken.Null:
|
case JsonToken.Null:
|
||||||
@@ -433,7 +435,7 @@ namespace Newtonsoft.Json
|
|||||||
return ReadInt32String(s);
|
return ReadInt32String(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw JsonReaderException.Create(this, "Error reading integer. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
|
throw JsonReaderException.Create(this, "Error reading integer. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int? ReadInt32String(string s)
|
internal int? ReadInt32String(string s)
|
||||||
@@ -632,7 +634,7 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
|
|
||||||
double d;
|
double d;
|
||||||
if (double.TryParse(s, NumberStyles.Float, Culture, out d))
|
if (double.TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, Culture, out d))
|
||||||
{
|
{
|
||||||
SetToken(JsonToken.Float, d, false);
|
SetToken(JsonToken.Float, d, false);
|
||||||
return d;
|
return d;
|
||||||
|
|||||||
@@ -729,8 +729,8 @@ namespace Newtonsoft.Json
|
|||||||
|
|
||||||
internal virtual void PopulateInternal(JsonReader reader, object target)
|
internal virtual void PopulateInternal(JsonReader reader, object target)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
ValidationUtils.ArgumentNotNull(target, "target");
|
ValidationUtils.ArgumentNotNull(target, nameof(target));
|
||||||
|
|
||||||
// set serialization options onto reader
|
// set serialization options onto reader
|
||||||
CultureInfo previousCulture;
|
CultureInfo previousCulture;
|
||||||
@@ -804,7 +804,7 @@ namespace Newtonsoft.Json
|
|||||||
|
|
||||||
internal virtual object DeserializeInternal(JsonReader reader, Type objectType)
|
internal virtual object DeserializeInternal(JsonReader reader, Type objectType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
// set serialization options onto reader
|
// set serialization options onto reader
|
||||||
CultureInfo previousCulture;
|
CultureInfo previousCulture;
|
||||||
@@ -996,7 +996,7 @@ namespace Newtonsoft.Json
|
|||||||
|
|
||||||
internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
|
internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(jsonWriter, "jsonWriter");
|
ValidationUtils.ArgumentNotNull(jsonWriter, nameof(jsonWriter));
|
||||||
|
|
||||||
// set serialization options onto writer
|
// set serialization options onto writer
|
||||||
Formatting? previousFormatting = null;
|
Formatting? previousFormatting = null;
|
||||||
@@ -1109,7 +1109,7 @@ namespace Newtonsoft.Json
|
|||||||
internal static JsonConverter GetMatchingConverter(IList<JsonConverter> converters, Type objectType)
|
internal static JsonConverter GetMatchingConverter(IList<JsonConverter> converters, Type objectType)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
ValidationUtils.ArgumentNotNull(objectType, "objectType");
|
ValidationUtils.ArgumentNotNull(objectType, nameof(objectType));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (converters != null)
|
if (converters != null)
|
||||||
|
|||||||
@@ -528,7 +528,7 @@ namespace Newtonsoft.Json
|
|||||||
// eat
|
// eat
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
case State.Finished:
|
case State.Finished:
|
||||||
ReadFinished();
|
ReadFinished();
|
||||||
SetToken(JsonToken.None);
|
SetToken(JsonToken.None);
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="reader">The <see cref="JsonReader"/> to read from while validating.</param>
|
/// <param name="reader">The <see cref="JsonReader"/> to read from while validating.</param>
|
||||||
public JsonValidatingReader(JsonReader reader)
|
public JsonValidatingReader(JsonReader reader)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
_stack = new Stack<SchemaScope>();
|
_stack = new Stack<SchemaScope>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ namespace Newtonsoft.Json
|
|||||||
/// <param name="writeChildren">A flag indicating whether the current token's children should be written.</param>
|
/// <param name="writeChildren">A flag indicating whether the current token's children should be written.</param>
|
||||||
public void WriteToken(JsonReader reader, bool writeChildren)
|
public void WriteToken(JsonReader reader, bool writeChildren)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
WriteToken(reader, writeChildren, true, true);
|
WriteToken(reader, writeChildren, true, true);
|
||||||
}
|
}
|
||||||
@@ -520,18 +520,18 @@ namespace Newtonsoft.Json
|
|||||||
WriteStartArray();
|
WriteStartArray();
|
||||||
break;
|
break;
|
||||||
case JsonToken.StartConstructor:
|
case JsonToken.StartConstructor:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
WriteStartConstructor(value.ToString());
|
WriteStartConstructor(value.ToString());
|
||||||
break;
|
break;
|
||||||
case JsonToken.PropertyName:
|
case JsonToken.PropertyName:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
WritePropertyName(value.ToString());
|
WritePropertyName(value.ToString());
|
||||||
break;
|
break;
|
||||||
case JsonToken.Comment:
|
case JsonToken.Comment:
|
||||||
WriteComment((value != null) ? value.ToString() : null);
|
WriteComment((value != null) ? value.ToString() : null);
|
||||||
break;
|
break;
|
||||||
case JsonToken.Integer:
|
case JsonToken.Integer:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||||
if (value is BigInteger)
|
if (value is BigInteger)
|
||||||
{
|
{
|
||||||
@@ -544,7 +544,7 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JsonToken.Float:
|
case JsonToken.Float:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
if (value is decimal)
|
if (value is decimal)
|
||||||
{
|
{
|
||||||
WriteValue((decimal)value);
|
WriteValue((decimal)value);
|
||||||
@@ -563,11 +563,11 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case JsonToken.String:
|
case JsonToken.String:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
WriteValue(value.ToString());
|
WriteValue(value.ToString());
|
||||||
break;
|
break;
|
||||||
case JsonToken.Boolean:
|
case JsonToken.Boolean:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
WriteValue(Convert.ToBoolean(value, CultureInfo.InvariantCulture));
|
WriteValue(Convert.ToBoolean(value, CultureInfo.InvariantCulture));
|
||||||
break;
|
break;
|
||||||
case JsonToken.Null:
|
case JsonToken.Null:
|
||||||
@@ -586,7 +586,7 @@ namespace Newtonsoft.Json
|
|||||||
WriteEndConstructor();
|
WriteEndConstructor();
|
||||||
break;
|
break;
|
||||||
case JsonToken.Date:
|
case JsonToken.Date:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
#if !NET20
|
#if !NET20
|
||||||
if (value is DateTimeOffset)
|
if (value is DateTimeOffset)
|
||||||
{
|
{
|
||||||
@@ -602,7 +602,7 @@ namespace Newtonsoft.Json
|
|||||||
WriteRawValue((value != null) ? value.ToString() : null);
|
WriteRawValue((value != null) ? value.ToString() : null);
|
||||||
break;
|
break;
|
||||||
case JsonToken.Bytes:
|
case JsonToken.Bytes:
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
if (value is Guid)
|
if (value is Guid)
|
||||||
{
|
{
|
||||||
WriteValue((Guid)value);
|
WriteValue((Guid)value);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the ancestors of every token in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the ancestors of every token in the source collection.</returns>
|
||||||
public static IJEnumerable<JToken> Ancestors<T>(this IEnumerable<T> source) where T : JToken
|
public static IJEnumerable<JToken> Ancestors<T>(this IEnumerable<T> source) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(j => j.Ancestors()).AsJEnumerable();
|
return source.SelectMany(j => j.Ancestors()).AsJEnumerable();
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains every token in the source collection, the ancestors of every token in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains every token in the source collection, the ancestors of every token in the source collection.</returns>
|
||||||
public static IJEnumerable<JToken> AncestorsAndSelf<T>(this IEnumerable<T> source) where T : JToken
|
public static IJEnumerable<JToken> AncestorsAndSelf<T>(this IEnumerable<T> source) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(j => j.AncestorsAndSelf()).AsJEnumerable();
|
return source.SelectMany(j => j.AncestorsAndSelf()).AsJEnumerable();
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the descendants of every token in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains the descendants of every token in the source collection.</returns>
|
||||||
public static IJEnumerable<JToken> Descendants<T>(this IEnumerable<T> source) where T : JContainer
|
public static IJEnumerable<JToken> Descendants<T>(this IEnumerable<T> source) where T : JContainer
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(j => j.Descendants()).AsJEnumerable();
|
return source.SelectMany(j => j.Descendants()).AsJEnumerable();
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains every token in the source collection, and the descendants of every token in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> that contains every token in the source collection, and the descendants of every token in the source collection.</returns>
|
||||||
public static IJEnumerable<JToken> DescendantsAndSelf<T>(this IEnumerable<T> source) where T : JContainer
|
public static IJEnumerable<JToken> DescendantsAndSelf<T>(this IEnumerable<T> source) where T : JContainer
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(j => j.DescendantsAndSelf()).AsJEnumerable();
|
return source.SelectMany(j => j.DescendantsAndSelf()).AsJEnumerable();
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JProperty"/> that contains the properties of every object in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JProperty"/> that contains the properties of every object in the source collection.</returns>
|
||||||
public static IJEnumerable<JProperty> Properties(this IEnumerable<JObject> source)
|
public static IJEnumerable<JProperty> Properties(this IEnumerable<JObject> source)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(d => d.Properties()).AsJEnumerable();
|
return source.SelectMany(d => d.Properties()).AsJEnumerable();
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>A converted value.</returns>
|
/// <returns>A converted value.</returns>
|
||||||
public static U Value<T, U>(this IEnumerable<T> value) where T : JToken
|
public static U Value<T, U>(this IEnumerable<T> value) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "source");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
JToken token = value as JToken;
|
JToken token = value as JToken;
|
||||||
if (token == null)
|
if (token == null)
|
||||||
@@ -182,7 +182,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
internal static IEnumerable<U> Values<T, U>(this IEnumerable<T> source, object key) where T : JToken
|
internal static IEnumerable<U> Values<T, U>(this IEnumerable<T> source, object key) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
foreach (JToken token in source)
|
foreach (JToken token in source)
|
||||||
{
|
{
|
||||||
@@ -236,14 +236,14 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>An <see cref="IEnumerable{T}"/> that contains the converted values of every token in the source collection.</returns>
|
/// <returns>An <see cref="IEnumerable{T}"/> that contains the converted values of every token in the source collection.</returns>
|
||||||
public static IEnumerable<U> Children<T, U>(this IEnumerable<T> source) where T : JToken
|
public static IEnumerable<U> Children<T, U>(this IEnumerable<T> source) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
return source.SelectMany(c => c.Children()).Convert<JToken, U>();
|
return source.SelectMany(c => c.Children()).Convert<JToken, U>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IEnumerable<U> Convert<T, U>(this IEnumerable<T> source) where T : JToken
|
internal static IEnumerable<U> Convert<T, U>(this IEnumerable<T> source) where T : JToken
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
|
|
||||||
foreach (T token in source)
|
foreach (T token in source)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
if (!(key is int))
|
if (!(key is int))
|
||||||
{
|
{
|
||||||
@@ -249,7 +249,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
if (!(key is int))
|
if (!(key is int))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -126,7 +126,15 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <param name="name">The constructor name.</param>
|
/// <param name="name">The constructor name.</param>
|
||||||
public JConstructor(string name)
|
public JConstructor(string name)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNullOrEmpty(name, "name");
|
if (name == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Constructor name cannot be empty.", nameof(name));
|
||||||
|
}
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
@@ -167,7 +175,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
if (!(key is int))
|
if (!(key is int))
|
||||||
{
|
{
|
||||||
@@ -178,7 +186,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
if (!(key is int))
|
if (!(key is int))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
internal JContainer(JContainer other)
|
internal JContainer(JContainer other)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(other, "c");
|
ValidationUtils.ArgumentNotNull(other, nameof(other));
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (JToken child in other)
|
foreach (JToken child in other)
|
||||||
@@ -644,7 +644,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
internal virtual void ValidateToken(JToken o, JToken existing)
|
internal virtual void ValidateToken(JToken o, JToken existing)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(o, "o");
|
ValidationUtils.ArgumentNotNull(o, nameof(o));
|
||||||
|
|
||||||
if (o.Type == JTokenType.Property)
|
if (o.Type == JTokenType.Property)
|
||||||
{
|
{
|
||||||
@@ -775,7 +775,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings)
|
internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(r, "r");
|
ValidationUtils.ArgumentNotNull(r, nameof(r));
|
||||||
IJsonLineInfo lineInfo = r as IJsonLineInfo;
|
IJsonLineInfo lineInfo = r as IJsonLineInfo;
|
||||||
|
|
||||||
JContainer parent = this;
|
JContainer parent = this;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <param name="enumerable">The enumerable.</param>
|
/// <param name="enumerable">The enumerable.</param>
|
||||||
public JEnumerable(IEnumerable<T> enumerable)
|
public JEnumerable(IEnumerable<T> enumerable)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(enumerable, "enumerable");
|
ValidationUtils.ArgumentNotNull(enumerable, nameof(enumerable));
|
||||||
|
|
||||||
_enumerable = enumerable;
|
_enumerable = enumerable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
internal override void ValidateToken(JToken o, JToken existing)
|
internal override void ValidateToken(JToken o, JToken existing)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(o, "o");
|
ValidationUtils.ArgumentNotNull(o, nameof(o));
|
||||||
|
|
||||||
if (o.Type != JTokenType.Property)
|
if (o.Type != JTokenType.Property)
|
||||||
{
|
{
|
||||||
@@ -285,7 +285,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
string propertyName = key as string;
|
string propertyName = key as string;
|
||||||
if (propertyName == null)
|
if (propertyName == null)
|
||||||
@@ -297,7 +297,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(key, "o");
|
ValidationUtils.ArgumentNotNull(key, nameof(key));
|
||||||
|
|
||||||
string propertyName = key as string;
|
string propertyName = key as string;
|
||||||
if (propertyName == null)
|
if (propertyName == null)
|
||||||
@@ -317,7 +317,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyName, "propertyName");
|
ValidationUtils.ArgumentNotNull(propertyName, nameof(propertyName));
|
||||||
|
|
||||||
JProperty property = Property(propertyName);
|
JProperty property = Property(propertyName);
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>A <see cref="JObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
|
/// <returns>A <see cref="JObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
|
||||||
public new static JObject Load(JsonReader reader, JsonLoadSettings settings)
|
public new static JObject Load(JsonReader reader, JsonLoadSettings settings)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
if (reader.TokenType == JsonToken.None)
|
if (reader.TokenType == JsonToken.None)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
internal JProperty(string name)
|
internal JProperty(string name)
|
||||||
{
|
{
|
||||||
// called from JTokenWriter
|
// called from JTokenWriter
|
||||||
ValidationUtils.ArgumentNotNull(name, "name");
|
ValidationUtils.ArgumentNotNull(name, nameof(name));
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <param name="content">The property content.</param>
|
/// <param name="content">The property content.</param>
|
||||||
public JProperty(string name, object content)
|
public JProperty(string name, object content)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(name, "name");
|
ValidationUtils.ArgumentNotNull(name, nameof(name));
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
|
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
private static string GetType(JToken token)
|
private static string GetType(JToken token)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(token, "token");
|
ValidationUtils.ArgumentNotNull(token, nameof(token));
|
||||||
|
|
||||||
if (token is JProperty)
|
if (token is JProperty)
|
||||||
{
|
{
|
||||||
@@ -1888,8 +1888,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
internal static JToken FromObjectInternal(object o, JsonSerializer jsonSerializer)
|
internal static JToken FromObjectInternal(object o, JsonSerializer jsonSerializer)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(o, "o");
|
ValidationUtils.ArgumentNotNull(o, nameof(o));
|
||||||
ValidationUtils.ArgumentNotNull(jsonSerializer, "jsonSerializer");
|
ValidationUtils.ArgumentNotNull(jsonSerializer, nameof(jsonSerializer));
|
||||||
|
|
||||||
JToken token;
|
JToken token;
|
||||||
using (JTokenWriter jsonWriter = new JTokenWriter())
|
using (JTokenWriter jsonWriter = new JTokenWriter())
|
||||||
@@ -2074,7 +2074,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <returns>The new object created from the JSON value.</returns>
|
/// <returns>The new object created from the JSON value.</returns>
|
||||||
public object ToObject(Type objectType, JsonSerializer jsonSerializer)
|
public object ToObject(Type objectType, JsonSerializer jsonSerializer)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(jsonSerializer, "jsonSerializer");
|
ValidationUtils.ArgumentNotNull(jsonSerializer, nameof(jsonSerializer));
|
||||||
|
|
||||||
using (JTokenReader jsonReader = new JTokenReader(this))
|
using (JTokenReader jsonReader = new JTokenReader(this))
|
||||||
{
|
{
|
||||||
@@ -2109,7 +2109,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public static JToken ReadFrom(JsonReader reader, JsonLoadSettings settings)
|
public static JToken ReadFrom(JsonReader reader, JsonLoadSettings settings)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
if (reader.TokenType == JsonToken.None)
|
if (reader.TokenType == JsonToken.None)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <param name="token">The token to read from.</param>
|
/// <param name="token">The token to read from.</param>
|
||||||
public JTokenReader(JToken token)
|
public JTokenReader(JToken token)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(token, "token");
|
ValidationUtils.ArgumentNotNull(token, nameof(token));
|
||||||
|
|
||||||
_root = token;
|
_root = token;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// <param name="container">The container being written to.</param>
|
/// <param name="container">The container being written to.</param>
|
||||||
public JTokenWriter(JContainer container)
|
public JTokenWriter(JContainer container)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(container, "container");
|
ValidationUtils.ArgumentNotNull(container, nameof(container));
|
||||||
|
|
||||||
_token = container;
|
_token = container;
|
||||||
_parent = container;
|
_parent = container;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
|||||||
|
|
||||||
public JPath(string expression)
|
public JPath(string expression)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(expression, "expression");
|
ValidationUtils.ArgumentNotNull(expression, nameof(expression));
|
||||||
_expression = expression;
|
_expression = expression;
|
||||||
Filters = new List<PathFilter>();
|
Filters = new List<PathFilter>();
|
||||||
|
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
[Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")]
|
[Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")]
|
||||||
public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
|
public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(source, "source");
|
ValidationUtils.ArgumentNotNull(source, nameof(source));
|
||||||
ValidationUtils.ArgumentNotNull(schema, "schema");
|
ValidationUtils.ArgumentNotNull(schema, nameof(schema));
|
||||||
|
|
||||||
using (JsonValidatingReader reader = new JsonValidatingReader(source.CreateReader()))
|
using (JsonValidatingReader reader = new JsonValidatingReader(source.CreateReader()))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
/// <returns>The <see cref="JsonSchema"/> object representing the JSON Schema.</returns>
|
/// <returns>The <see cref="JsonSchema"/> object representing the JSON Schema.</returns>
|
||||||
public static JsonSchema Read(JsonReader reader, JsonSchemaResolver resolver)
|
public static JsonSchema Read(JsonReader reader, JsonSchemaResolver resolver)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
ValidationUtils.ArgumentNotNull(resolver, "resolver");
|
ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));
|
||||||
|
|
||||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(resolver);
|
JsonSchemaBuilder builder = new JsonSchemaBuilder(resolver);
|
||||||
return builder.Read(reader);
|
return builder.Read(reader);
|
||||||
@@ -305,7 +305,7 @@ namespace Newtonsoft.Json.Schema
|
|||||||
/// <returns>A <see cref="JsonSchema"/> populated from the string that contains JSON.</returns>
|
/// <returns>A <see cref="JsonSchema"/> populated from the string that contains JSON.</returns>
|
||||||
public static JsonSchema Parse(string json, JsonSchemaResolver resolver)
|
public static JsonSchema Parse(string json, JsonSchemaResolver resolver)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(json, "json");
|
ValidationUtils.ArgumentNotNull(json, nameof(json));
|
||||||
|
|
||||||
using (JsonReader reader = new JsonTextReader(new StringReader(json)))
|
using (JsonReader reader = new JsonTextReader(new StringReader(json)))
|
||||||
{
|
{
|
||||||
@@ -329,8 +329,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
/// <param name="resolver">The resolver used.</param>
|
/// <param name="resolver">The resolver used.</param>
|
||||||
public void WriteTo(JsonWriter writer, JsonSchemaResolver resolver)
|
public void WriteTo(JsonWriter writer, JsonSchemaResolver resolver)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(writer, "writer");
|
ValidationUtils.ArgumentNotNull(writer, nameof(writer));
|
||||||
ValidationUtils.ArgumentNotNull(resolver, "resolver");
|
ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));
|
||||||
|
|
||||||
JsonSchemaWriter schemaWriter = new JsonSchemaWriter(writer, resolver);
|
JsonSchemaWriter schemaWriter = new JsonSchemaWriter(writer, resolver);
|
||||||
schemaWriter.WriteSchema(this);
|
schemaWriter.WriteSchema(this);
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
|
|
||||||
public TypeSchema(Type type, JsonSchema schema)
|
public TypeSchema(Type type, JsonSchema schema)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
ValidationUtils.ArgumentNotNull(schema, "schema");
|
ValidationUtils.ArgumentNotNull(schema, nameof(schema));
|
||||||
|
|
||||||
Type = type;
|
Type = type;
|
||||||
Schema = schema;
|
Schema = schema;
|
||||||
@@ -164,8 +164,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
/// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
|
/// <returns>A <see cref="JsonSchema"/> generated from the specified type.</returns>
|
||||||
public JsonSchema Generate(Type type, JsonSchemaResolver resolver, bool rootSchemaNullable)
|
public JsonSchema Generate(Type type, JsonSchemaResolver resolver, bool rootSchemaNullable)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
ValidationUtils.ArgumentNotNull(resolver, "resolver");
|
ValidationUtils.ArgumentNotNull(resolver, nameof(resolver));
|
||||||
|
|
||||||
_resolver = resolver;
|
_resolver = resolver;
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ namespace Newtonsoft.Json.Schema
|
|||||||
|
|
||||||
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
|
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
|
|
||||||
string resolvedId = GetTypeId(type, false);
|
string resolvedId = GetTypeId(type, false);
|
||||||
string explicitId = GetTypeId(type, true);
|
string explicitId = GetTypeId(type, true);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Schema
|
|||||||
|
|
||||||
public JsonSchemaWriter(JsonWriter writer, JsonSchemaResolver resolver)
|
public JsonSchemaWriter(JsonWriter writer, JsonSchemaResolver resolver)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(writer, "writer");
|
ValidationUtils.ArgumentNotNull(writer, nameof(writer));
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
_resolver = resolver;
|
_resolver = resolver;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ namespace Newtonsoft.Json.Schema
|
|||||||
|
|
||||||
public void WriteSchema(JsonSchema schema)
|
public void WriteSchema(JsonSchema schema)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(schema, "schema");
|
ValidationUtils.ArgumentNotNull(schema, nameof(schema));
|
||||||
|
|
||||||
if (!_resolver.LoadedSchemas.Contains(schema))
|
if (!_resolver.LoadedSchemas.Contains(schema))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Schema
|
|||||||
|
|
||||||
internal ValidationEventArgs(JsonSchemaException ex)
|
internal ValidationEventArgs(JsonSchemaException ex)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(ex, "ex");
|
ValidationUtils.ArgumentNotNull(ex, nameof(ex));
|
||||||
_ex = ex;
|
_ex = ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -582,7 +582,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public DictionaryEnumerator(IEnumerable<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> e)
|
public DictionaryEnumerator(IEnumerable<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> e)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(e, "e");
|
ValidationUtils.ArgumentNotNull(e, nameof(e));
|
||||||
_e = e.GetEnumerator();
|
_e = e.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
/// <param name="memberInfo">The member info.</param>
|
/// <param name="memberInfo">The member info.</param>
|
||||||
public DynamicValueProvider(MemberInfo memberInfo)
|
public DynamicValueProvider(MemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(memberInfo, "memberInfo");
|
ValidationUtils.ArgumentNotNull(memberInfo, nameof(memberInfo));
|
||||||
_memberInfo = memberInfo;
|
_memberInfo = memberInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
/// <param name="memberInfo">The member info.</param>
|
/// <param name="memberInfo">The member info.</param>
|
||||||
public ExpressionValueProvider(MemberInfo memberInfo)
|
public ExpressionValueProvider(MemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(memberInfo, "memberInfo");
|
ValidationUtils.ArgumentNotNull(memberInfo, nameof(memberInfo));
|
||||||
_memberInfo = memberInfo;
|
_memberInfo = memberInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
internal JsonContract(Type underlyingType)
|
internal JsonContract(Type underlyingType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(underlyingType, "underlyingType");
|
ValidationUtils.ArgumentNotNull(underlyingType, nameof(underlyingType));
|
||||||
|
|
||||||
UnderlyingType = underlyingType;
|
UnderlyingType = underlyingType;
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
internal bool TryGetMember(IDynamicMetaObjectProvider dynamicProvider, string name, out object value)
|
internal bool TryGetMember(IDynamicMetaObjectProvider dynamicProvider, string name, out object value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dynamicProvider, "dynamicProvider");
|
ValidationUtils.ArgumentNotNull(dynamicProvider, nameof(dynamicProvider));
|
||||||
|
|
||||||
CallSite<Func<CallSite, object, object>> callSite = _callSiteGetters.Get(name);
|
CallSite<Func<CallSite, object, object>> callSite = _callSiteGetters.Get(name);
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
internal bool TrySetMember(IDynamicMetaObjectProvider dynamicProvider, string name, object value)
|
internal bool TrySetMember(IDynamicMetaObjectProvider dynamicProvider, string name, object value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dynamicProvider, "dynamicProvider");
|
ValidationUtils.ArgumentNotNull(dynamicProvider, nameof(dynamicProvider));
|
||||||
|
|
||||||
CallSite<Func<CallSite, object, object, object>> callSite = _callSiteSetters.Get(name);
|
CallSite<Func<CallSite, object, object, object>> callSite = _callSiteSetters.Get(name);
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public JsonFormatterConverter(JsonSerializerInternalReader reader, JsonISerializableContract contract, JsonProperty member)
|
public JsonFormatterConverter(JsonSerializerInternalReader reader, JsonISerializableContract contract, JsonProperty member)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "serializer");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
ValidationUtils.ArgumentNotNull(contract, "contract");
|
ValidationUtils.ArgumentNotNull(contract, nameof(contract));
|
||||||
|
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
_contract = contract;
|
_contract = contract;
|
||||||
@@ -50,7 +50,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private T GetTokenValue<T>(object value)
|
private T GetTokenValue<T>(object value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
JValue v = (JValue)value;
|
JValue v = (JValue)value;
|
||||||
return (T)System.Convert.ChangeType(v.Value, typeof(T), CultureInfo.InvariantCulture);
|
return (T)System.Convert.ChangeType(v.Value, typeof(T), CultureInfo.InvariantCulture);
|
||||||
@@ -58,7 +58,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public object Convert(object value, Type type)
|
public object Convert(object value, Type type)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
JToken token = value as JToken;
|
JToken token = value as JToken;
|
||||||
if (token == null)
|
if (token == null)
|
||||||
@@ -71,7 +71,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public object Convert(object value, TypeCode typeCode)
|
public object Convert(object value, TypeCode typeCode)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(value, "value");
|
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||||
|
|
||||||
if (value is JValue)
|
if (value is JValue)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
protected JsonSerializerInternalBase(JsonSerializer serializer)
|
protected JsonSerializerInternalBase(JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(serializer, "serializer");
|
ValidationUtils.ArgumentNotNull(serializer, nameof(serializer));
|
||||||
|
|
||||||
Serializer = serializer;
|
Serializer = serializer;
|
||||||
TraceWriter = serializer.TraceWriter;
|
TraceWriter = serializer.TraceWriter;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public void Populate(JsonReader reader, object target)
|
public void Populate(JsonReader reader, object target)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(target, "target");
|
ValidationUtils.ArgumentNotNull(target, nameof(target));
|
||||||
|
|
||||||
Type objectType = target.GetType();
|
Type objectType = target.GetType();
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private JToken CreateJToken(JsonReader reader, JsonContract contract)
|
private JToken CreateJToken(JsonReader reader, JsonContract contract)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
if (contract != null)
|
if (contract != null)
|
||||||
{
|
{
|
||||||
@@ -234,7 +234,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private JToken CreateJObject(JsonReader reader)
|
private JToken CreateJObject(JsonReader reader)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(reader, "reader");
|
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
|
||||||
|
|
||||||
// this is needed because we've already read inside the object, looking for metadata properties
|
// this is needed because we've already read inside the object, looking for metadata properties
|
||||||
using (JTokenWriter writer = new JTokenWriter())
|
using (JTokenWriter writer = new JTokenWriter())
|
||||||
@@ -1884,7 +1884,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
private object CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor<object> creator, string id)
|
private object CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor<object> creator, string id)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(creator, "creator");
|
ValidationUtils.ArgumentNotNull(creator, nameof(creator));
|
||||||
|
|
||||||
// only need to keep a track of properies presence if they are required or a value should be defaulted if missing
|
// only need to keep a track of properies presence if they are required or a value should be defaulted if missing
|
||||||
bool trackPresence = (contract.HasRequiredOrDefaultValueProperties || HasFlag(Serializer._defaultValueHandling, DefaultValueHandling.Populate));
|
bool trackPresence = (contract.HasRequiredOrDefaultValueProperties || HasFlag(Serializer._defaultValueHandling, DefaultValueHandling.Populate));
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public JsonSerializerProxy(JsonSerializerInternalReader serializerReader)
|
public JsonSerializerProxy(JsonSerializerInternalReader serializerReader)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(serializerReader, "serializerReader");
|
ValidationUtils.ArgumentNotNull(serializerReader, nameof(serializerReader));
|
||||||
|
|
||||||
_serializerReader = serializerReader;
|
_serializerReader = serializerReader;
|
||||||
_serializer = serializerReader.Serializer;
|
_serializer = serializerReader.Serializer;
|
||||||
@@ -233,7 +233,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
|
|
||||||
public JsonSerializerProxy(JsonSerializerInternalWriter serializerWriter)
|
public JsonSerializerProxy(JsonSerializerInternalWriter serializerWriter)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(serializerWriter, "serializerWriter");
|
ValidationUtils.ArgumentNotNull(serializerWriter, nameof(serializerWriter));
|
||||||
|
|
||||||
_serializerWriter = serializerWriter;
|
_serializerWriter = serializerWriter;
|
||||||
_serializer = serializerWriter.Serializer;
|
_serializer = serializerWriter.Serializer;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
/// <param name="attributeProvider">The instance to get attributes for. This parameter should be a <see cref="System.Type"/>, <see cref="MemberInfo"/>, <see cref="ParameterInfo"/> or <see cref="Assembly"/>.</param>
|
/// <param name="attributeProvider">The instance to get attributes for. This parameter should be a <see cref="System.Type"/>, <see cref="MemberInfo"/>, <see cref="ParameterInfo"/> or <see cref="Assembly"/>.</param>
|
||||||
public ReflectionAttributeProvider(object attributeProvider)
|
public ReflectionAttributeProvider(object attributeProvider)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(attributeProvider, "attributeProvider");
|
ValidationUtils.ArgumentNotNull(attributeProvider, nameof(attributeProvider));
|
||||||
_attributeProvider = attributeProvider;
|
_attributeProvider = attributeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
/// <param name="memberInfo">The member info.</param>
|
/// <param name="memberInfo">The member info.</param>
|
||||||
public ReflectionValueProvider(MemberInfo memberInfo)
|
public ReflectionValueProvider(MemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(memberInfo, "memberInfo");
|
ValidationUtils.ArgumentNotNull(memberInfo, nameof(memberInfo));
|
||||||
_memberInfo = memberInfo;
|
_memberInfo = memberInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public Base64Encoder(TextWriter writer)
|
public Base64Encoder(TextWriter writer)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(writer, "writer");
|
ValidationUtils.ArgumentNotNull(writer, nameof(writer));
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if (NET20 || NET35 || PORTABLE40)
|
#if (NET20 || NET35 || PORTABLE40)
|
||||||
public static void AddRange<T>(this IList<T> initial, IEnumerable collection)
|
public static void AddRange<T>(this IList<T> initial, IEnumerable collection)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(initial, "initial");
|
ValidationUtils.ArgumentNotNull(initial, nameof(initial));
|
||||||
|
|
||||||
// because earlier versions of .NET didn't support covariant generics
|
// because earlier versions of .NET didn't support covariant generics
|
||||||
initial.AddRange(collection.Cast<T>());
|
initial.AddRange(collection.Cast<T>());
|
||||||
@@ -92,7 +92,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool IsDictionaryType(Type type)
|
public static bool IsDictionaryType(Type type)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
|
|
||||||
if (typeof(IDictionary).IsAssignableFrom(type))
|
if (typeof(IDictionary).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public CollectionWrapper(IList list)
|
public CollectionWrapper(IList list)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(list, "list");
|
ValidationUtils.ArgumentNotNull(list, nameof(list));
|
||||||
|
|
||||||
if (list is ICollection<T>)
|
if (list is ICollection<T>)
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public CollectionWrapper(ICollection<T> list)
|
public CollectionWrapper(ICollection<T> list)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(list, "list");
|
ValidationUtils.ArgumentNotNull(list, nameof(list));
|
||||||
|
|
||||||
_genericCollection = list;
|
_genericCollection = list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public DictionaryWrapper(IDictionary dictionary)
|
public DictionaryWrapper(IDictionary dictionary)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dictionary, "dictionary");
|
ValidationUtils.ArgumentNotNull(dictionary, nameof(dictionary));
|
||||||
|
|
||||||
_dictionary = dictionary;
|
_dictionary = dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DictionaryWrapper(IDictionary<TKey, TValue> dictionary)
|
public DictionaryWrapper(IDictionary<TKey, TValue> dictionary)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dictionary, "dictionary");
|
ValidationUtils.ArgumentNotNull(dictionary, nameof(dictionary));
|
||||||
|
|
||||||
_genericDictionary = dictionary;
|
_genericDictionary = dictionary;
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
#if !(NET40 || NET35 || NET20 || PORTABLE40)
|
#if !(NET40 || NET35 || NET20 || PORTABLE40)
|
||||||
public DictionaryWrapper(IReadOnlyDictionary<TKey, TValue> dictionary)
|
public DictionaryWrapper(IReadOnlyDictionary<TKey, TValue> dictionary)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dictionary, "dictionary");
|
ValidationUtils.ArgumentNotNull(dictionary, nameof(dictionary));
|
||||||
|
|
||||||
_readOnlyDictionary = dictionary;
|
_readOnlyDictionary = dictionary;
|
||||||
}
|
}
|
||||||
@@ -478,7 +478,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public DictionaryEnumerator(IEnumerator<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> e)
|
public DictionaryEnumerator(IEnumerator<KeyValuePair<TEnumeratorKey, TEnumeratorValue>> e)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(e, "e");
|
ValidationUtils.ArgumentNotNull(e, nameof(e));
|
||||||
_e = e;
|
_e = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,10 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
throw new ArgumentNullException(nameof(enumType));
|
throw new ArgumentNullException(nameof(enumType));
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidationUtils.ArgumentTypeIsEnum(enumType, "enumType");
|
if (!enumType.IsEnum())
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Type {0} is not an Enum.".FormatWith(CultureInfo.InvariantCulture, enumType), nameof(enumType));
|
||||||
|
}
|
||||||
|
|
||||||
IList<object> enumValues = GetValues(enumType);
|
IList<object> enumValues = GetValues(enumType);
|
||||||
IList<string> enumNames = GetNames(enumType);
|
IList<string> enumNames = GetNames(enumType);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method)
|
public override ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(method, "method");
|
ValidationUtils.ArgumentNotNull(method, nameof(method));
|
||||||
|
|
||||||
Type type = typeof(object);
|
Type type = typeof(object);
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override MethodCall<T, object> CreateMethodCall<T>(MethodBase method)
|
public override MethodCall<T, object> CreateMethodCall<T>(MethodBase method)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(method, "method");
|
ValidationUtils.ArgumentNotNull(method, nameof(method));
|
||||||
|
|
||||||
Type type = typeof(object);
|
Type type = typeof(object);
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
Type instanceType = typeof(T);
|
Type instanceType = typeof(T);
|
||||||
Type resultType = typeof(object);
|
Type resultType = typeof(object);
|
||||||
@@ -253,7 +253,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo");
|
ValidationUtils.ArgumentNotNull(fieldInfo, nameof(fieldInfo));
|
||||||
|
|
||||||
ParameterExpression sourceParameter = Expression.Parameter(typeof(T), "source");
|
ParameterExpression sourceParameter = Expression.Parameter(typeof(T), "source");
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo");
|
ValidationUtils.ArgumentNotNull(fieldInfo, nameof(fieldInfo));
|
||||||
|
|
||||||
// use reflection for structs
|
// use reflection for structs
|
||||||
// expression doesn't correctly set value
|
// expression doesn't correctly set value
|
||||||
@@ -313,7 +313,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
// use reflection for structs
|
// use reflection for structs
|
||||||
// expression doesn't correctly set value
|
// expression doesn't correctly set value
|
||||||
|
|||||||
@@ -303,11 +303,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToEscapedJavaScriptString(string value, char delimiter, bool appendDelimiters)
|
|
||||||
{
|
|
||||||
return ToEscapedJavaScriptString(value, delimiter, appendDelimiters, StringEscapeHandling.Default);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToEscapedJavaScriptString(string value, char delimiter, bool appendDelimiters, StringEscapeHandling stringEscapeHandling)
|
public static string ToEscapedJavaScriptString(string value, char delimiter, bool appendDelimiters, StringEscapeHandling stringEscapeHandling)
|
||||||
{
|
{
|
||||||
bool[] charEscapeFlags = GetCharEscapeFlags(stringEscapeHandling, delimiter);
|
bool[] charEscapeFlags = GetCharEscapeFlags(stringEscapeHandling, delimiter);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method)
|
public override ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(method, "method");
|
ValidationUtils.ArgumentNotNull(method, nameof(method));
|
||||||
|
|
||||||
ConstructorInfo c = method as ConstructorInfo;
|
ConstructorInfo c = method as ConstructorInfo;
|
||||||
if (c != null)
|
if (c != null)
|
||||||
@@ -63,7 +63,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override MethodCall<T, object> CreateMethodCall<T>(MethodBase method)
|
public override MethodCall<T, object> CreateMethodCall<T>(MethodBase method)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(method, "method");
|
ValidationUtils.ArgumentNotNull(method, nameof(method));
|
||||||
|
|
||||||
ConstructorInfo c = method as ConstructorInfo;
|
ConstructorInfo c = method as ConstructorInfo;
|
||||||
if (c != null)
|
if (c != null)
|
||||||
@@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Func<T> CreateDefaultConstructor<T>(Type type)
|
public override Func<T> CreateDefaultConstructor<T>(Type type)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
|
|
||||||
if (type.IsValueType())
|
if (type.IsValueType())
|
||||||
{
|
{
|
||||||
@@ -90,28 +90,28 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
public override Func<T, object> CreateGet<T>(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
return o => propertyInfo.GetValue(o, null);
|
return o => propertyInfo.GetValue(o, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
public override Func<T, object> CreateGet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo");
|
ValidationUtils.ArgumentNotNull(fieldInfo, nameof(fieldInfo));
|
||||||
|
|
||||||
return o => fieldInfo.GetValue(o);
|
return o => fieldInfo.GetValue(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
public override Action<T, object> CreateSet<T>(FieldInfo fieldInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo");
|
ValidationUtils.ArgumentNotNull(fieldInfo, nameof(fieldInfo));
|
||||||
|
|
||||||
return (o, v) => fieldInfo.SetValue(o, v);
|
return (o, v) => fieldInfo.SetValue(o, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
public override Action<T, object> CreateSet<T>(PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
return (o, v) => propertyInfo.SetValue(o, v, null);
|
return (o, v) => propertyInfo.SetValue(o, v, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool IsVirtual(this PropertyInfo propertyInfo)
|
public static bool IsVirtual(this PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
MethodInfo m = propertyInfo.GetGetMethod();
|
MethodInfo m = propertyInfo.GetGetMethod();
|
||||||
if (m != null && m.IsVirtual)
|
if (m != null && m.IsVirtual)
|
||||||
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static MethodInfo GetBaseDefinition(this PropertyInfo propertyInfo)
|
public static MethodInfo GetBaseDefinition(this PropertyInfo propertyInfo)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo");
|
ValidationUtils.ArgumentNotNull(propertyInfo, nameof(propertyInfo));
|
||||||
|
|
||||||
MethodInfo m = propertyInfo.GetGetMethod();
|
MethodInfo m = propertyInfo.GetGetMethod();
|
||||||
if (m != null)
|
if (m != null)
|
||||||
@@ -227,7 +227,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool HasDefaultConstructor(Type t, bool nonPublic)
|
public static bool HasDefaultConstructor(Type t, bool nonPublic)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(t, "t");
|
ValidationUtils.ArgumentNotNull(t, nameof(t));
|
||||||
|
|
||||||
if (t.IsValueType())
|
if (t.IsValueType())
|
||||||
{
|
{
|
||||||
@@ -255,7 +255,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool IsNullable(Type t)
|
public static bool IsNullable(Type t)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(t, "t");
|
ValidationUtils.ArgumentNotNull(t, nameof(t));
|
||||||
|
|
||||||
if (t.IsValueType())
|
if (t.IsValueType())
|
||||||
{
|
{
|
||||||
@@ -267,7 +267,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool IsNullableType(Type t)
|
public static bool IsNullableType(Type t)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(t, "t");
|
ValidationUtils.ArgumentNotNull(t, nameof(t));
|
||||||
|
|
||||||
return (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(Nullable<>));
|
return (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(Nullable<>));
|
||||||
}
|
}
|
||||||
@@ -298,8 +298,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition, out Type implementingType)
|
public static bool ImplementsGenericDefinition(Type type, Type genericInterfaceDefinition, out Type implementingType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
ValidationUtils.ArgumentNotNull(genericInterfaceDefinition, "genericInterfaceDefinition");
|
ValidationUtils.ArgumentNotNull(genericInterfaceDefinition, nameof(genericInterfaceDefinition));
|
||||||
|
|
||||||
if (!genericInterfaceDefinition.IsInterface() || !genericInterfaceDefinition.IsGenericTypeDefinition())
|
if (!genericInterfaceDefinition.IsInterface() || !genericInterfaceDefinition.IsGenericTypeDefinition())
|
||||||
{
|
{
|
||||||
@@ -346,8 +346,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition, out Type implementingType)
|
public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition, out Type implementingType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
ValidationUtils.ArgumentNotNull(genericClassDefinition, "genericClassDefinition");
|
ValidationUtils.ArgumentNotNull(genericClassDefinition, nameof(genericClassDefinition));
|
||||||
|
|
||||||
if (!genericClassDefinition.IsClass() || !genericClassDefinition.IsGenericTypeDefinition())
|
if (!genericClassDefinition.IsClass() || !genericClassDefinition.IsGenericTypeDefinition())
|
||||||
{
|
{
|
||||||
@@ -386,7 +386,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// <returns>The type of the typed collection's items.</returns>
|
/// <returns>The type of the typed collection's items.</returns>
|
||||||
public static Type GetCollectionItemType(Type type)
|
public static Type GetCollectionItemType(Type type)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(type, "type");
|
ValidationUtils.ArgumentNotNull(type, nameof(type));
|
||||||
Type genericListType;
|
Type genericListType;
|
||||||
|
|
||||||
if (type.IsArray)
|
if (type.IsArray)
|
||||||
@@ -412,7 +412,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static void GetDictionaryKeyValueTypes(Type dictionaryType, out Type keyType, out Type valueType)
|
public static void GetDictionaryKeyValueTypes(Type dictionaryType, out Type keyType, out Type valueType)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(dictionaryType, "type");
|
ValidationUtils.ArgumentNotNull(dictionaryType, nameof(dictionaryType));
|
||||||
|
|
||||||
Type genericDictionaryType;
|
Type genericDictionaryType;
|
||||||
if (ImplementsGenericDefinition(dictionaryType, typeof(IDictionary<,>), out genericDictionaryType))
|
if (ImplementsGenericDefinition(dictionaryType, typeof(IDictionary<,>), out genericDictionaryType))
|
||||||
@@ -445,7 +445,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// <returns>The underlying type of the member.</returns>
|
/// <returns>The underlying type of the member.</returns>
|
||||||
public static Type GetMemberUnderlyingType(MemberInfo member)
|
public static Type GetMemberUnderlyingType(MemberInfo member)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(member, "member");
|
ValidationUtils.ArgumentNotNull(member, nameof(member));
|
||||||
|
|
||||||
switch (member.MemberType())
|
switch (member.MemberType())
|
||||||
{
|
{
|
||||||
@@ -471,7 +471,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public static bool IsIndexedProperty(MemberInfo member)
|
public static bool IsIndexedProperty(MemberInfo member)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(member, "member");
|
ValidationUtils.ArgumentNotNull(member, nameof(member));
|
||||||
|
|
||||||
PropertyInfo propertyInfo = member as PropertyInfo;
|
PropertyInfo propertyInfo = member as PropertyInfo;
|
||||||
|
|
||||||
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public static bool IsIndexedProperty(PropertyInfo property)
|
public static bool IsIndexedProperty(PropertyInfo property)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(property, "property");
|
ValidationUtils.ArgumentNotNull(property, nameof(property));
|
||||||
|
|
||||||
return (property.GetIndexParameters().Length > 0);
|
return (property.GetIndexParameters().Length > 0);
|
||||||
}
|
}
|
||||||
@@ -507,8 +507,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// <returns>The member's value on the object.</returns>
|
/// <returns>The member's value on the object.</returns>
|
||||||
public static object GetMemberValue(MemberInfo member, object target)
|
public static object GetMemberValue(MemberInfo member, object target)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(member, "member");
|
ValidationUtils.ArgumentNotNull(member, nameof(member));
|
||||||
ValidationUtils.ArgumentNotNull(target, "target");
|
ValidationUtils.ArgumentNotNull(target, nameof(target));
|
||||||
|
|
||||||
switch (member.MemberType())
|
switch (member.MemberType())
|
||||||
{
|
{
|
||||||
@@ -536,8 +536,8 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public static void SetMemberValue(MemberInfo member, object target, object value)
|
public static void SetMemberValue(MemberInfo member, object target, object value)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(member, "member");
|
ValidationUtils.ArgumentNotNull(member, nameof(member));
|
||||||
ValidationUtils.ArgumentNotNull(target, "target");
|
ValidationUtils.ArgumentNotNull(target, nameof(target));
|
||||||
|
|
||||||
switch (member.MemberType())
|
switch (member.MemberType())
|
||||||
{
|
{
|
||||||
@@ -755,7 +755,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static Attribute[] GetAttributes(object attributeProvider, Type attributeType, bool inherit)
|
public static Attribute[] GetAttributes(object attributeProvider, Type attributeType, bool inherit)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(attributeProvider, "attributeProvider");
|
ValidationUtils.ArgumentNotNull(attributeProvider, nameof(attributeProvider));
|
||||||
|
|
||||||
object provider = attributeProvider;
|
object provider = attributeProvider;
|
||||||
|
|
||||||
@@ -919,7 +919,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static IEnumerable<FieldInfo> GetFields(Type targetType, BindingFlags bindingAttr)
|
public static IEnumerable<FieldInfo> GetFields(Type targetType, BindingFlags bindingAttr)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(targetType, "targetType");
|
ValidationUtils.ArgumentNotNull(targetType, nameof(targetType));
|
||||||
|
|
||||||
List<MemberInfo> fieldInfos = new List<MemberInfo>(targetType.GetFields(bindingAttr));
|
List<MemberInfo> fieldInfos = new List<MemberInfo>(targetType.GetFields(bindingAttr));
|
||||||
#if !PORTABLE
|
#if !PORTABLE
|
||||||
@@ -955,7 +955,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
public static IEnumerable<PropertyInfo> GetProperties(Type targetType, BindingFlags bindingAttr)
|
public static IEnumerable<PropertyInfo> GetProperties(Type targetType, BindingFlags bindingAttr)
|
||||||
{
|
{
|
||||||
ValidationUtils.ArgumentNotNull(targetType, "targetType");
|
ValidationUtils.ArgumentNotNull(targetType, nameof(targetType));
|
||||||
|
|
||||||
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(targetType.GetProperties(bindingAttr));
|
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(targetType.GetProperties(bindingAttr));
|
||||||
|
|
||||||
|
|||||||
@@ -68,11 +68,6 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
internal static class StringReferenceExtensions
|
internal static class StringReferenceExtensions
|
||||||
{
|
{
|
||||||
public static int IndexOf(this StringReference s, char c)
|
|
||||||
{
|
|
||||||
return IndexOf(s, c, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int IndexOf(this StringReference s, char c, int startIndex, int length)
|
public static int IndexOf(this StringReference s, char c, int startIndex, int length)
|
||||||
{
|
{
|
||||||
int index = Array.IndexOf(s.Chars, c, s.StartIndex + startIndex, length);
|
int index = Array.IndexOf(s.Chars, c, s.StartIndex + startIndex, length);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
{
|
{
|
||||||
// leave this a private to force code to use an explicit overload
|
// leave this a private to force code to use an explicit overload
|
||||||
// avoids stack memory being reserved for the object array
|
// avoids stack memory being reserved for the object array
|
||||||
ValidationUtils.ArgumentNotNull(format, "format");
|
ValidationUtils.ArgumentNotNull(format, nameof(format));
|
||||||
|
|
||||||
return string.Format(provider, format, args);
|
return string.Format(provider, format, args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,38 +24,11 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Utilities
|
namespace Newtonsoft.Json.Utilities
|
||||||
{
|
{
|
||||||
internal static class ValidationUtils
|
internal static class ValidationUtils
|
||||||
{
|
{
|
||||||
public static void ArgumentNotNullOrEmpty(string value, string parameterName)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(parameterName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.Length == 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("'{0}' cannot be empty.".FormatWith(CultureInfo.InvariantCulture, parameterName), parameterName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ArgumentTypeIsEnum(Type enumType, string parameterName)
|
|
||||||
{
|
|
||||||
ArgumentNotNull(enumType, "enumType");
|
|
||||||
|
|
||||||
if (!enumType.IsEnum())
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Type {0} is not an Enum.".FormatWith(CultureInfo.InvariantCulture, enumType), parameterName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ArgumentNotNull(object value, string parameterName)
|
public static void ArgumentNotNull(object value, string parameterName)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user