diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/DeserializeConstructorHandling.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/DeserializeConstructorHandling.cs index 2b78fc26..74627772 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/DeserializeConstructorHandling.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Serializer/DeserializeConstructorHandling.cs @@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer { if (website == null) { - throw new ArgumentNullException("website"); + throw new ArgumentNullException(nameof(website)); } Url = website.Url; diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 34716ac4..53cc5680 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -1179,39 +1179,37 @@ third line", jsonTextReader.Value); Assert.AreEqual("type", reader.Value); } - public class FakeBufferPool : IJsonBufferPool + public class FakeArrayPool : IArrayPool { - public readonly List FreeBuffers = new List(); - public readonly List UsedBuffers = new List(); + public readonly List FreeArrays = new List(); + public readonly List UsedArrays = new List(); - public char[] RentBuffer(int minSize) + public char[] Rent(int minimumLength) { - char[] buffer = FreeBuffers.FirstOrDefault(b => b.Length >= minSize); - if (buffer != null) + char[] a = FreeArrays.FirstOrDefault(b => b.Length >= minimumLength); + if (a != null) { - FreeBuffers.Remove(buffer); - UsedBuffers.Add(buffer); + FreeArrays.Remove(a); + UsedArrays.Add(a); - return buffer; + return a; } - buffer = new char[minSize]; - UsedBuffers.Add(buffer); + a = new char[minimumLength]; + UsedArrays.Add(a); - return buffer; + return a; } - public void ReturnBuffer(ref char[] buffer) + public void Return(char[] array) { - if (UsedBuffers.Remove(buffer)) + if (UsedArrays.Remove(array)) { - FreeBuffers.Add(buffer); + FreeArrays.Add(array); - // smallest first so the first buffer large enough is rented - FreeBuffers.Sort((b1, b2) => Comparer.Default.Compare(b1.Length, b2.Length)); + // smallest first so the first array large enough is rented + FreeArrays.Sort((b1, b2) => Comparer.Default.Compare(b1.Length, b2.Length)); } - - buffer = null; } } @@ -1228,13 +1226,13 @@ third line", jsonTextReader.Value); ] }"; - FakeBufferPool bufferPool = new FakeBufferPool(); + FakeArrayPool arrayPool = new FakeArrayPool(); for (int i = 0; i < 1000; i++) { using (JsonTextReader reader = new JsonTextReader(new StringReader(json))) { - reader.BufferPool = bufferPool; + reader.ArrayPool = arrayPool; while (reader.Read()) { @@ -1243,12 +1241,12 @@ third line", jsonTextReader.Value); if ((i + 1) % 100 == 0) { - Console.WriteLine("Allocated buffers: " + bufferPool.FreeBuffers.Count); + Console.WriteLine("Allocated buffers: " + arrayPool.FreeArrays.Count); } } - Assert.AreEqual(0, bufferPool.UsedBuffers.Count); - Assert.AreEqual(6, bufferPool.FreeBuffers.Count); + Assert.AreEqual(0, arrayPool.UsedArrays.Count); + Assert.AreEqual(6, arrayPool.FreeArrays.Count); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index e5c58ec9..f01b9697 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -59,7 +59,7 @@ namespace Newtonsoft.Json.Tests [Test] public void BufferTest() { - JsonTextReaderTest.FakeBufferPool bufferPool = new JsonTextReaderTest.FakeBufferPool(); + JsonTextReaderTest.FakeArrayPool arrayPool = new JsonTextReaderTest.FakeArrayPool(); string longString = new string('A', 2000); string longEscapedString = "Hello!" + new string('!', 50) + new string('\n', 1000) + "Good bye!"; @@ -71,7 +71,7 @@ namespace Newtonsoft.Json.Tests using (JsonTextWriter writer = new JsonTextWriter(sw)) { - writer.BufferPool = bufferPool; + writer.ArrayPool = arrayPool; writer.WriteStartObject(); @@ -92,12 +92,12 @@ namespace Newtonsoft.Json.Tests if ((i + 1) % 100 == 0) { - Console.WriteLine("Allocated buffers: " + bufferPool.FreeBuffers.Count); + Console.WriteLine("Allocated buffers: " + arrayPool.FreeArrays.Count); } } - Assert.AreEqual(0, bufferPool.UsedBuffers.Count); - Assert.AreEqual(3, bufferPool.FreeBuffers.Count); + Assert.AreEqual(0, arrayPool.UsedArrays.Count); + Assert.AreEqual(3, arrayPool.FreeArrays.Count); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 4be5157d..5ffdb084 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -784,7 +784,7 @@ If attributes are not mentioned, default values are used in each case. json = SerializeBinaryFormatter(value); break; default: - throw new ArgumentOutOfRangeException("method"); + throw new ArgumentOutOfRangeException(nameof(method)); } return json; @@ -991,7 +991,7 @@ If attributes are not mentioned, default values are used in each case. case SerializeMethod.DataContractJsonSerializer: return DeserializeDataContractJson((string)json); default: - throw new ArgumentOutOfRangeException("method"); + throw new ArgumentOutOfRangeException(nameof(method)); } } diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaSpecTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaSpecTests.cs index 70466269..ff54fec6 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaSpecTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaSpecTests.cs @@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Tests.Schema [TestFixture] public class JsonSchemaSpecTests : TestFixtureBase { - [TestCaseSourceAttribute("GetSpecTestDetails")] + [TestCaseSourceAttribute(nameof(GetSpecTestDetails))] public void SpecTest(JsonSchemaSpecTest jsonSchemaSpecTest) { JsonSchema s = JsonSchema.Read(jsonSchemaSpecTest.Schema.CreateReader()); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 54d96deb..35403919 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -4514,7 +4514,7 @@ Path '', line 1, position 1."); { if (dictionary == null) { - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); } foreach (var entry in dictionary) @@ -8534,7 +8534,7 @@ Path '', line 1, position 1."); { if (bar == null) { - throw new ArgumentNullException("bar"); + throw new ArgumentNullException(nameof(bar)); } Bar = bar; diff --git a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs index eb521512..046c54f3 100644 --- a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs @@ -190,7 +190,7 @@ namespace Newtonsoft.Json.Bson } break; default: - throw new ArgumentOutOfRangeException("t", "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type)); + throw new ArgumentOutOfRangeException(nameof(t), "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type)); } } @@ -324,7 +324,7 @@ namespace Newtonsoft.Json.Bson return value.CalculatedSize; } default: - throw new ArgumentOutOfRangeException("t", "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type)); + throw new ArgumentOutOfRangeException(nameof(t), "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type)); } } } diff --git a/Src/Newtonsoft.Json/Bson/BsonObjectId.cs b/Src/Newtonsoft.Json/Bson/BsonObjectId.cs index 68bcd90b..a13ce099 100644 --- a/Src/Newtonsoft.Json/Bson/BsonObjectId.cs +++ b/Src/Newtonsoft.Json/Bson/BsonObjectId.cs @@ -48,7 +48,7 @@ namespace Newtonsoft.Json.Bson ValidationUtils.ArgumentNotNull(value, "value"); if (value.Length != 12) { - throw new ArgumentException("An ObjectId must be 12 bytes", "value"); + throw new ArgumentException("An ObjectId must be 12 bytes", nameof(value)); } Value = value; diff --git a/Src/Newtonsoft.Json/Bson/BsonReader.cs b/Src/Newtonsoft.Json/Bson/BsonReader.cs index 0e388c9d..f6deace3 100644 --- a/Src/Newtonsoft.Json/Bson/BsonReader.cs +++ b/Src/Newtonsoft.Json/Bson/BsonReader.cs @@ -623,7 +623,7 @@ namespace Newtonsoft.Json.Bson SetToken(JsonToken.Integer, ReadInt64()); break; default: - throw new ArgumentOutOfRangeException("type", "Unexpected BsonType value: " + type); + throw new ArgumentOutOfRangeException(nameof(type), "Unexpected BsonType value: " + type); } } diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index d482fe99..051f6768 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -985,7 +985,7 @@ namespace Newtonsoft.Json.Converters } #endif - throw new ArgumentException("Value must be an XML object.", "value"); + throw new ArgumentException("Value must be an XML object.", nameof(value)); } private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager) diff --git a/Src/Newtonsoft.Json/IArrayPool.cs b/Src/Newtonsoft.Json/IArrayPool.cs new file mode 100644 index 00000000..25e27bcb --- /dev/null +++ b/Src/Newtonsoft.Json/IArrayPool.cs @@ -0,0 +1,22 @@ +namespace Newtonsoft.Json +{ + /// + /// Provides an interface for using pooled arrays. + /// + /// The array type content. + public interface IArrayPool + { + /// + /// Rent a array from the pool. This array must be returned when it is no longer needed. + /// + /// The minimum required length of the array. The returned array may be larger. + /// The rented array from the pool. This array must be returned when it is no longer needed. + T[] Rent(int minimumLength); + + /// + /// Return an array to the pool. + /// + /// The array that is being returned. + void Return(T[] array); + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/IJsonBufferPool.cs b/Src/Newtonsoft.Json/IJsonBufferPool.cs deleted file mode 100644 index 36d4b47d..00000000 --- a/Src/Newtonsoft.Json/IJsonBufferPool.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Newtonsoft.Json -{ - /// - /// Provides an interface for using pooled buffers. - /// - /// The buffer type content. - public interface IJsonBufferPool - { - /// - /// Rent a buffer from the pool. This buffer must be returned when it is no longer needed. - /// - /// The minimum required size of the buffer. The returned buffer may be larger. - /// The rented buffer from the pool. - T[] RentBuffer(int minSize); - - /// - /// Return a buffer to the pool. - /// - /// The buffer that is being returned. - void ReturnBuffer(ref T[] buffer); - } -} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index bc95a19b..c49358de 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -444,7 +444,7 @@ namespace Newtonsoft.Json { if (delimiter != '"' && delimiter != '\'') { - throw new ArgumentException("Delimiter must be a single or double quote.", "delimiter"); + throw new ArgumentException("Delimiter must be a single or double quote.", nameof(delimiter)); } return JavaScriptUtils.ToEscapedJavaScriptString(value, delimiter, true, stringEscapeHandling); diff --git a/Src/Newtonsoft.Json/JsonConverterAttribute.cs b/Src/Newtonsoft.Json/JsonConverterAttribute.cs index 42891923..fdafb3a4 100644 --- a/Src/Newtonsoft.Json/JsonConverterAttribute.cs +++ b/Src/Newtonsoft.Json/JsonConverterAttribute.cs @@ -60,7 +60,7 @@ namespace Newtonsoft.Json { if (converterType == null) { - throw new ArgumentNullException("converterType"); + throw new ArgumentNullException(nameof(converterType)); } _converterType = converterType; diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index 3e99b5bb..f9109ce8 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -177,7 +177,7 @@ namespace Newtonsoft.Json { if (value < DateTimeZoneHandling.Local || value > DateTimeZoneHandling.RoundtripKind) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _dateTimeZoneHandling = value; @@ -200,7 +200,7 @@ namespace Newtonsoft.Json #endif ) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _dateParseHandling = value; @@ -217,7 +217,7 @@ namespace Newtonsoft.Json { if (value < FloatParseHandling.Double || value > FloatParseHandling.Decimal) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _floatParseHandling = value; @@ -243,7 +243,7 @@ namespace Newtonsoft.Json { if (value <= 0) { - throw new ArgumentException("Value must be positive.", "value"); + throw new ArgumentException("Value must be positive.", nameof(value)); } _maxDepth = value; diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 8aa4f63e..b487ddc8 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -91,7 +91,7 @@ namespace Newtonsoft.Json { if (value == null) { - throw new ArgumentNullException("value", "Reference resolver cannot be null."); + throw new ArgumentNullException(nameof(value), "Reference resolver cannot be null."); } _referenceResolver = value; @@ -108,7 +108,7 @@ namespace Newtonsoft.Json { if (value == null) { - throw new ArgumentNullException("value", "Serialization binder cannot be null."); + throw new ArgumentNullException(nameof(value), "Serialization binder cannot be null."); } _binder = value; @@ -145,7 +145,7 @@ namespace Newtonsoft.Json { if (value < TypeNameHandling.None || value > TypeNameHandling.Auto) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _typeNameHandling = value; @@ -163,7 +163,7 @@ namespace Newtonsoft.Json { if (value < FormatterAssemblyStyle.Simple || value > FormatterAssemblyStyle.Full) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _typeNameAssemblyFormat = value; @@ -180,7 +180,7 @@ namespace Newtonsoft.Json { if (value < PreserveReferencesHandling.None || value > PreserveReferencesHandling.All) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _preserveReferencesHandling = value; @@ -197,7 +197,7 @@ namespace Newtonsoft.Json { if (value < ReferenceLoopHandling.Error || value > ReferenceLoopHandling.Serialize) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _referenceLoopHandling = value; @@ -214,7 +214,7 @@ namespace Newtonsoft.Json { if (value < MissingMemberHandling.Ignore || value > MissingMemberHandling.Error) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _missingMemberHandling = value; @@ -231,7 +231,7 @@ namespace Newtonsoft.Json { if (value < NullValueHandling.Include || value > NullValueHandling.Ignore) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _nullValueHandling = value; @@ -248,7 +248,7 @@ namespace Newtonsoft.Json { if (value < DefaultValueHandling.Include || value > DefaultValueHandling.IgnoreAndPopulate) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _defaultValueHandling = value; @@ -266,7 +266,7 @@ namespace Newtonsoft.Json { if (value < ObjectCreationHandling.Auto || value > ObjectCreationHandling.Replace) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _objectCreationHandling = value; @@ -284,7 +284,7 @@ namespace Newtonsoft.Json { if (value < ConstructorHandling.Default || value > ConstructorHandling.AllowNonPublicDefaultConstructor) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _constructorHandling = value; @@ -302,7 +302,7 @@ namespace Newtonsoft.Json { if (value < MetadataPropertyHandling.Default || value > MetadataPropertyHandling.Ignore) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _metadataPropertyHandling = value; @@ -443,7 +443,7 @@ namespace Newtonsoft.Json { if (value <= 0) { - throw new ArgumentException("Value must be positive.", "value"); + throw new ArgumentException("Value must be positive.", nameof(value)); } _maxDepth = value; diff --git a/Src/Newtonsoft.Json/JsonSerializerSettings.cs b/Src/Newtonsoft.Json/JsonSerializerSettings.cs index e9cc00cc..aa996c37 100644 --- a/Src/Newtonsoft.Json/JsonSerializerSettings.cs +++ b/Src/Newtonsoft.Json/JsonSerializerSettings.cs @@ -287,7 +287,7 @@ namespace Newtonsoft.Json { if (value <= 0) { - throw new ArgumentException("Value must be positive.", "value"); + throw new ArgumentException("Value must be positive.", nameof(value)); } _maxDepth = value; diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index d0c4fb1f..e6d377b1 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -64,7 +64,7 @@ namespace Newtonsoft.Json private bool _isEndOfFile; private StringBuffer _stringBuffer; private StringReference _stringReference; - private IJsonBufferPool _bufferPool; + private IArrayPool _arrayPool; internal PropertyNameTable NameTable; /// @@ -75,7 +75,7 @@ namespace Newtonsoft.Json { if (reader == null) { - throw new ArgumentNullException("reader"); + throw new ArgumentNullException(nameof(reader)); } _reader = reader; @@ -92,17 +92,17 @@ namespace Newtonsoft.Json /// /// Gets or sets the reader's character buffer pool. /// - public IJsonBufferPool BufferPool + public IArrayPool ArrayPool { - get { return _bufferPool; } + get { return _arrayPool; } set { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } - _bufferPool = value; + _arrayPool = value; } } @@ -110,7 +110,7 @@ namespace Newtonsoft.Json { if (_stringBuffer.IsEmpty) { - _stringBuffer = new StringBuffer(_bufferPool, 1024); + _stringBuffer = new StringBuffer(_arrayPool, 1024); } } @@ -249,11 +249,11 @@ namespace Newtonsoft.Json int newArrayLength = Math.Max(_chars.Length * 2, _charsUsed + charsRequired + 1); // increase the size of the buffer - char[] dst = BufferUtils.RentBuffer(_bufferPool, newArrayLength); + char[] dst = BufferUtils.RentBuffer(_arrayPool, newArrayLength); BlockCopyChars(_chars, 0, dst, 0, _chars.Length); - BufferUtils.ReturnBuffer(_bufferPool, ref _chars); + BufferUtils.ReturnBuffer(_arrayPool, _chars); _chars = dst; } @@ -264,14 +264,14 @@ namespace Newtonsoft.Json if (remainingCharCount + charsRequired + 1 >= _chars.Length) { // the remaining count plus the required is bigger than the current buffer size - char[] dst = BufferUtils.RentBuffer(_bufferPool, remainingCharCount + charsRequired + 1); + char[] dst = BufferUtils.RentBuffer(_arrayPool, remainingCharCount + charsRequired + 1); if (remainingCharCount > 0) { BlockCopyChars(_chars, _charPos, dst, 0, remainingCharCount); } - BufferUtils.ReturnBuffer(_bufferPool, ref _chars); + BufferUtils.ReturnBuffer(_arrayPool, _chars); _chars = dst; } @@ -429,7 +429,7 @@ namespace Newtonsoft.Json { if (_chars == null) { - _chars = BufferUtils.RentBuffer(_bufferPool, 1024); + _chars = BufferUtils.RentBuffer(_arrayPool, 1024); _chars[0] = '\0'; } @@ -644,7 +644,7 @@ namespace Newtonsoft.Json if (charPos > lastWritePosition) { - _stringBuffer.Append(_bufferPool, _chars, lastWritePosition, charPos - lastWritePosition); + _stringBuffer.Append(_arrayPool, _chars, lastWritePosition, charPos - lastWritePosition); } _stringReference = new StringReference(_stringBuffer.InternalBuffer, 0, _stringBuffer.Position); @@ -663,10 +663,10 @@ namespace Newtonsoft.Json { if (writeToPosition > lastWritePosition) { - _stringBuffer.Append(_bufferPool, _chars, lastWritePosition, writeToPosition - lastWritePosition); + _stringBuffer.Append(_arrayPool, _chars, lastWritePosition, writeToPosition - lastWritePosition); } - _stringBuffer.Append(_bufferPool, writeChar); + _stringBuffer.Append(_arrayPool, writeChar); } private char ParseUnicode() @@ -1759,7 +1759,8 @@ namespace Newtonsoft.Json if (_chars != null) { - BufferUtils.ReturnBuffer(_bufferPool, ref _chars); + BufferUtils.ReturnBuffer(_arrayPool, _chars); + _chars = null; } if (CloseInput && _reader != null) @@ -1771,7 +1772,7 @@ namespace Newtonsoft.Json #endif } - _stringBuffer.Clear(_bufferPool); + _stringBuffer.Clear(_arrayPool); } /// diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs index 6e5b634f..b39b1d0f 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.cs @@ -49,7 +49,7 @@ namespace Newtonsoft.Json private bool _quoteName; private bool[] _charEscapeFlags; private char[] _writeBuffer; - private IJsonBufferPool _bufferPool; + private IArrayPool _arrayPool; private char[] _indentChars; private Base64Encoder Base64Encoder @@ -66,19 +66,19 @@ namespace Newtonsoft.Json } /// - /// Gets or sets the writer's character buffer pool. + /// Gets or sets the writer's character array pool. /// - public IJsonBufferPool BufferPool + public IArrayPool ArrayPool { - get { return _bufferPool; } + get { return _arrayPool; } set { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } - _bufferPool = value; + _arrayPool = value; } } @@ -150,7 +150,7 @@ namespace Newtonsoft.Json { if (textWriter == null) { - throw new ArgumentNullException("textWriter"); + throw new ArgumentNullException(nameof(textWriter)); } _writer = textWriter; @@ -177,7 +177,11 @@ namespace Newtonsoft.Json { base.Close(); - BufferUtils.ReturnBuffer(_bufferPool, ref _writeBuffer); + if (_writeBuffer != null) + { + BufferUtils.ReturnBuffer(_arrayPool, _writeBuffer); + _writeBuffer = null; + } if (CloseOutput && _writer != null) { @@ -418,7 +422,7 @@ namespace Newtonsoft.Json private void WriteEscapedString(string value, bool quote) { EnsureWriteBuffer(); - JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, quote, _charEscapeFlags, StringEscapeHandling, _bufferPool, ref _writeBuffer); + JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, quote, _charEscapeFlags, StringEscapeHandling, _arrayPool, ref _writeBuffer); } /// @@ -754,7 +758,7 @@ namespace Newtonsoft.Json if (_writeBuffer == null) { // maximum buffer sized used when writing iso date - _writeBuffer = BufferUtils.RentBuffer(_bufferPool, 35); + _writeBuffer = BufferUtils.RentBuffer(_arrayPool, 35); } } diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs index cb040ca5..a8dea103 100644 --- a/Src/Newtonsoft.Json/JsonWriter.cs +++ b/Src/Newtonsoft.Json/JsonWriter.cs @@ -230,7 +230,7 @@ namespace Newtonsoft.Json { if (value < Formatting.None || value > Formatting.Indented) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _formatting = value; @@ -247,7 +247,7 @@ namespace Newtonsoft.Json { if (value < DateFormatHandling.IsoDateFormat || value > DateFormatHandling.MicrosoftDateFormat) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _dateFormatHandling = value; @@ -264,7 +264,7 @@ namespace Newtonsoft.Json { if (value < DateTimeZoneHandling.Local || value > DateTimeZoneHandling.RoundtripKind) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _dateTimeZoneHandling = value; @@ -281,7 +281,7 @@ namespace Newtonsoft.Json { if (value < StringEscapeHandling.Default || value > StringEscapeHandling.EscapeHtml) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _stringEscapeHandling = value; @@ -306,7 +306,7 @@ namespace Newtonsoft.Json { if (value < FloatFormatHandling.String || value > FloatFormatHandling.DefaultValue) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _floatFormatHandling = value; @@ -1632,7 +1632,7 @@ namespace Newtonsoft.Json case JsonToken.PropertyName: if (!(value is string)) { - throw new ArgumentException("A name is required when setting property name state.", "value"); + throw new ArgumentException("A name is required when setting property name state.", nameof(value)); } InternalWritePropertyName((string)value); @@ -1663,7 +1663,7 @@ namespace Newtonsoft.Json InternalWriteEnd(JsonContainerType.Constructor); break; default: - throw new ArgumentOutOfRangeException("token"); + throw new ArgumentOutOfRangeException(nameof(token)); } } diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index a0bc3928..07f306e4 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -382,7 +382,7 @@ namespace Newtonsoft.Json.Linq if (index > children.Count) { - throw new ArgumentOutOfRangeException("index", "Index must be within the bounds of the List."); + throw new ArgumentOutOfRangeException(nameof(index), "Index must be within the bounds of the List."); } CheckReentrancy(); @@ -431,11 +431,11 @@ namespace Newtonsoft.Json.Linq if (index < 0) { - throw new ArgumentOutOfRangeException("index", "Index is less than 0."); + throw new ArgumentOutOfRangeException(nameof(index), "Index is less than 0."); } if (index >= children.Count) { - throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count."); + throw new ArgumentOutOfRangeException(nameof(index), "Index is equal to or greater than Count."); } CheckReentrancy(); @@ -496,11 +496,11 @@ namespace Newtonsoft.Json.Linq if (index < 0) { - throw new ArgumentOutOfRangeException("index", "Index is less than 0."); + throw new ArgumentOutOfRangeException(nameof(index), "Index is less than 0."); } if (index >= children.Count) { - throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count."); + throw new ArgumentOutOfRangeException(nameof(index), "Index is equal to or greater than Count."); } JToken existing = children[index]; @@ -602,11 +602,11 @@ namespace Newtonsoft.Json.Linq { if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } if (arrayIndex < 0) { - throw new ArgumentOutOfRangeException("arrayIndex", "arrayIndex is less than 0."); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), "arrayIndex is less than 0."); } if (arrayIndex >= array.Length && arrayIndex != 0) { @@ -1249,7 +1249,7 @@ namespace Newtonsoft.Json.Linq } break; default: - throw new ArgumentOutOfRangeException("settings", "Unexpected merge array handling when merging JSON."); + throw new ArgumentOutOfRangeException(nameof(settings), "Unexpected merge array handling when merging JSON."); } } } diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 2ce3970c..f8d8e86c 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -627,11 +627,11 @@ namespace Newtonsoft.Json.Linq { if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } if (arrayIndex < 0) { - throw new ArgumentOutOfRangeException("arrayIndex", "arrayIndex is less than 0."); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), "arrayIndex is less than 0."); } if (arrayIndex >= array.Length && arrayIndex != 0) { diff --git a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs index 796156d4..867d741c 100644 --- a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs +++ b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs @@ -77,7 +77,7 @@ namespace Newtonsoft.Json.Linq { if (key == null) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); } if (_dictionary != null) @@ -123,7 +123,7 @@ namespace Newtonsoft.Json.Linq { if (key == null) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); } if (_dictionary != null) @@ -179,7 +179,7 @@ namespace Newtonsoft.Json.Linq { if (key == null) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); } if (_dictionary != null) diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 2ac39468..90d06676 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -456,7 +456,7 @@ namespace Newtonsoft.Json.Linq { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (value is JProperty) @@ -2411,7 +2411,7 @@ namespace Newtonsoft.Json.Linq { if (annotation == null) { - throw new ArgumentNullException("annotation"); + throw new ArgumentNullException(nameof(annotation)); } if (_annotations == null) @@ -2484,7 +2484,7 @@ namespace Newtonsoft.Json.Linq { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } if (_annotations != null) @@ -2568,7 +2568,7 @@ namespace Newtonsoft.Json.Linq { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } if (_annotations == null) @@ -2662,7 +2662,7 @@ namespace Newtonsoft.Json.Linq { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } if (_annotations != null) diff --git a/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs b/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs index 4b5dd370..5f2e70ff 100644 --- a/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs @@ -21,7 +21,7 @@ namespace Newtonsoft.Json.Linq { if (value < CommentHandling.Ignore || value > CommentHandling.Load) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _commentHandling = value; @@ -39,7 +39,7 @@ namespace Newtonsoft.Json.Linq { if (value < LineInfoHandling.Ignore || value > LineInfoHandling.Load) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _lineInfoHandling = value; diff --git a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs index 5acfb173..c86175c5 100644 --- a/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs +++ b/Src/Newtonsoft.Json/Linq/JsonMergeSettings.cs @@ -20,7 +20,7 @@ namespace Newtonsoft.Json.Linq { if (value < MergeArrayHandling.Concat || value > MergeArrayHandling.Merge) { - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); } _mergeArrayHandling = value; diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj index b021c39f..5e9b73de 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -103,7 +103,7 @@ - + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 992a1bc1..e970986c 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -116,7 +116,7 @@ - + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj index c179f238..24b34563 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj @@ -113,7 +113,7 @@ - + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj index 958ebb72..d3e5d2cd 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -77,7 +77,7 @@ - + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj index 38753c02..eae7deab 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj @@ -82,7 +82,7 @@ - + diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index cb3996a4..b87c7e45 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -81,7 +81,7 @@ - + diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index ce8be0cb..f4cd8df3 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -236,7 +236,7 @@ namespace Newtonsoft.Json.Serialization { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } DefaultContractResolverState state = GetState(); diff --git a/Src/Newtonsoft.Json/Serialization/DiagnosticsTraceWriter.cs b/Src/Newtonsoft.Json/Serialization/DiagnosticsTraceWriter.cs index 72388ba1..b0293387 100644 --- a/Src/Newtonsoft.Json/Serialization/DiagnosticsTraceWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/DiagnosticsTraceWriter.cs @@ -33,7 +33,7 @@ namespace Newtonsoft.Json.Serialization case TraceLevel.Verbose: return TraceEventType.Verbose; default: - throw new ArgumentOutOfRangeException("level"); + throw new ArgumentOutOfRangeException(nameof(level)); } } diff --git a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs index def59481..f39201ea 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs @@ -63,7 +63,7 @@ namespace Newtonsoft.Json.Serialization JToken token = value as JToken; if (token == null) { - throw new ArgumentException("Value is not a JToken.", "value"); + throw new ArgumentException("Value is not a JToken.", nameof(value)); } return _reader.CreateISerializableItem(token, type, _contract, _member); diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 4c78b805..a4a6123a 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -140,7 +140,7 @@ namespace Newtonsoft.Json.Serialization { if (reader == null) { - throw new ArgumentNullException("reader"); + throw new ArgumentNullException(nameof(reader)); } JsonContract contract = GetContractSafe(objectType); diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index 74eaf54d..06407709 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -61,7 +61,7 @@ namespace Newtonsoft.Json.Serialization { if (jsonWriter == null) { - throw new ArgumentNullException("jsonWriter"); + throw new ArgumentNullException(nameof(jsonWriter)); } _rootType = objectType; diff --git a/Src/Newtonsoft.Json/Utilities/Base64Encoder.cs b/Src/Newtonsoft.Json/Utilities/Base64Encoder.cs index 1826fe49..7bad0516 100644 --- a/Src/Newtonsoft.Json/Utilities/Base64Encoder.cs +++ b/Src/Newtonsoft.Json/Utilities/Base64Encoder.cs @@ -49,22 +49,22 @@ namespace Newtonsoft.Json.Utilities { if (buffer == null) { - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); } if (index < 0) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } if (count < 0) { - throw new ArgumentOutOfRangeException("count"); + throw new ArgumentOutOfRangeException(nameof(count)); } if (count > (buffer.Length - index)) { - throw new ArgumentOutOfRangeException("count"); + throw new ArgumentOutOfRangeException(nameof(count)); } if (_leftOverBytesCount > 0) diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index f064839a..01acbad9 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -66,7 +66,7 @@ namespace Newtonsoft.Json.Utilities { if (initial == null) { - throw new ArgumentNullException("initial"); + throw new ArgumentNullException(nameof(initial)); } if (collection == null) @@ -170,7 +170,7 @@ namespace Newtonsoft.Json.Utilities if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } foreach (TSource local in source) diff --git a/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs b/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs index 6268b011..97c37811 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionWrapper.cs @@ -316,7 +316,7 @@ namespace Newtonsoft.Json.Utilities { if (!IsCompatibleObject(value)) { - throw new ArgumentException("The value '{0}' is not of type '{1}' and cannot be used in this generic collection.".FormatWith(CultureInfo.InvariantCulture, value, typeof(T)), "value"); + throw new ArgumentException("The value '{0}' is not of type '{1}' and cannot be used in this generic collection.".FormatWith(CultureInfo.InvariantCulture, value, typeof(T)), nameof(value)); } } diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index c5e04bf9..77f413ce 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -407,7 +407,7 @@ namespace Newtonsoft.Json.Utilities case ConvertResult.CannotConvertNull: throw new Exception("Can not convert null {0} into non-nullable {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType)); case ConvertResult.NotInstantiableType: - throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType"); + throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), nameof(targetType)); case ConvertResult.NoValidConversion: throw new InvalidOperationException("Can not convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType)); default: @@ -438,7 +438,7 @@ namespace Newtonsoft.Json.Utilities { if (initialValue == null) { - throw new ArgumentNullException("initialValue"); + throw new ArgumentNullException(nameof(initialValue)); } if (ReflectionUtils.IsNullableType(targetType)) diff --git a/Src/Newtonsoft.Json/Utilities/EnumUtils.cs b/Src/Newtonsoft.Json/Utilities/EnumUtils.cs index 1cfd7bf2..cb05b96a 100644 --- a/Src/Newtonsoft.Json/Utilities/EnumUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/EnumUtils.cs @@ -121,7 +121,7 @@ namespace Newtonsoft.Json.Utilities { if (enumType == null) { - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); } ValidationUtils.ArgumentTypeIsEnum(enumType, "enumType"); diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index ecca8141..313b5047 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -41,42 +41,40 @@ namespace Newtonsoft.Json.Utilities { internal static class BufferUtils { - public static char[] RentBuffer(IJsonBufferPool bufferPool, int minSize) + public static char[] RentBuffer(IArrayPool bufferPool, int minSize) { if (bufferPool == null) { return new char[minSize]; } - char[] buffer = bufferPool.RentBuffer(minSize); + char[] buffer = bufferPool.Rent(minSize); return buffer; } - public static void ReturnBuffer(IJsonBufferPool bufferPool, ref char[] buffer) + public static void ReturnBuffer(IArrayPool bufferPool, char[] buffer) { if (bufferPool == null) { - buffer = null; return; } - bufferPool.ReturnBuffer(ref buffer); + bufferPool.Return(buffer); } - public static void EnsureBufferSize(IJsonBufferPool bufferPool, int size, ref char[] buffer) + public static char[] EnsureBufferSize(IArrayPool bufferPool, int size, char[] buffer) { if (bufferPool == null) { - buffer = new char[size]; - return; + return new char[size]; } if (buffer != null) { - bufferPool.ReturnBuffer(ref buffer); + bufferPool.Return(buffer); } - buffer = bufferPool.RentBuffer(size); + return bufferPool.Rent(size); } } @@ -149,7 +147,7 @@ namespace Newtonsoft.Json.Utilities } public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters, - bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IJsonBufferPool bufferPool, ref char[] writeBuffer) + bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool bufferPool, ref char[] writeBuffer) { // leading delimiter if (appendDelimiters) @@ -216,7 +214,7 @@ namespace Newtonsoft.Json.Utilities { if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength) { - BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, ref writeBuffer); + writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer); } StringUtils.ToCharAsUnicode(c, writeBuffer); @@ -255,7 +253,7 @@ namespace Newtonsoft.Json.Utilities Array.Copy(writeBuffer, newBuffer, UnicodeTextLength); } - BufferUtils.ReturnBuffer(bufferPool, ref writeBuffer); + BufferUtils.ReturnBuffer(bufferPool, writeBuffer); writeBuffer = newBuffer; } diff --git a/Src/Newtonsoft.Json/Utilities/PropertyNameTable.cs b/Src/Newtonsoft.Json/Utilities/PropertyNameTable.cs index d017b602..4f1d2fc7 100644 --- a/Src/Newtonsoft.Json/Utilities/PropertyNameTable.cs +++ b/Src/Newtonsoft.Json/Utilities/PropertyNameTable.cs @@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Utilities { if (key == null) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); } int length = key.Length; diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index 737dc39d..a491c5f8 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -458,7 +458,7 @@ namespace Newtonsoft.Json.Utilities case MemberTypes.Method: return ((MethodInfo)member).ReturnType; default: - throw new ArgumentException("MemberInfo must be of type FieldInfo, PropertyInfo, EventInfo or MethodInfo", "member"); + throw new ArgumentException("MemberInfo must be of type FieldInfo, PropertyInfo, EventInfo or MethodInfo", nameof(member)); } } @@ -524,7 +524,7 @@ namespace Newtonsoft.Json.Utilities throw new ArgumentException("MemberInfo '{0}' has index parameters".FormatWith(CultureInfo.InvariantCulture, member.Name), e); } default: - throw new ArgumentException("MemberInfo '{0}' is not of type FieldInfo or PropertyInfo".FormatWith(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture, member.Name), "member"); + throw new ArgumentException("MemberInfo '{0}' is not of type FieldInfo or PropertyInfo".FormatWith(CultureInfo.InvariantCulture, CultureInfo.InvariantCulture, member.Name), nameof(member)); } } @@ -548,7 +548,7 @@ namespace Newtonsoft.Json.Utilities ((PropertyInfo)member).SetValue(target, value, null); break; default: - throw new ArgumentException("MemberInfo '{0}' must be of type FieldInfo or PropertyInfo".FormatWith(CultureInfo.InvariantCulture, member.Name), "member"); + throw new ArgumentException("MemberInfo '{0}' must be of type FieldInfo or PropertyInfo".FormatWith(CultureInfo.InvariantCulture, member.Name), nameof(member)); } } diff --git a/Src/Newtonsoft.Json/Utilities/StringBuffer.cs b/Src/Newtonsoft.Json/Utilities/StringBuffer.cs index b28f3fc6..ec6818e8 100644 --- a/Src/Newtonsoft.Json/Utilities/StringBuffer.cs +++ b/Src/Newtonsoft.Json/Utilities/StringBuffer.cs @@ -46,7 +46,7 @@ namespace Newtonsoft.Json.Utilities get { return _buffer == null; } } - public StringBuffer(IJsonBufferPool bufferPool, int initalSize) : this(BufferUtils.RentBuffer(bufferPool, initalSize)) + public StringBuffer(IArrayPool bufferPool, int initalSize) : this(BufferUtils.RentBuffer(bufferPool, initalSize)) { } @@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Utilities _position = 0; } - public void Append(IJsonBufferPool bufferPool, char value) + public void Append(IArrayPool bufferPool, char value) { // test if the buffer array is large enough to take the value if (_position == _buffer.Length) @@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Utilities _buffer[_position++] = value; } - public void Append(IJsonBufferPool bufferPool, char[] buffer, int startIndex, int count) + public void Append(IArrayPool bufferPool, char[] buffer, int startIndex, int count) { if (_position + count >= _buffer.Length) { @@ -80,24 +80,24 @@ namespace Newtonsoft.Json.Utilities _position += count; } - public void Clear(IJsonBufferPool bufferPool) + public void Clear(IArrayPool bufferPool) { if (_buffer != null) { - BufferUtils.ReturnBuffer(bufferPool, ref _buffer); + BufferUtils.ReturnBuffer(bufferPool, _buffer); _buffer = null; } _position = 0; } - private void EnsureSize(IJsonBufferPool bufferPool, int appendLength) + private void EnsureSize(IArrayPool bufferPool, int appendLength) { char[] newBuffer = BufferUtils.RentBuffer(bufferPool, (_position + appendLength) * 2); if (_buffer != null) { Array.Copy(_buffer, newBuffer, _position); - BufferUtils.ReturnBuffer(bufferPool, ref _buffer); + BufferUtils.ReturnBuffer(bufferPool, _buffer); } _buffer = newBuffer; diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index 0e2f5961..53adce4c 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -85,7 +85,7 @@ namespace Newtonsoft.Json.Utilities { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (s.Length == 0) @@ -148,11 +148,11 @@ namespace Newtonsoft.Json.Utilities { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (valueSelector == null) { - throw new ArgumentNullException("valueSelector"); + throw new ArgumentNullException(nameof(valueSelector)); } var caseInsensitiveResults = source.Where(s => string.Equals(valueSelector(s), testValue, StringComparison.OrdinalIgnoreCase)); diff --git a/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs b/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs index f956dec1..1e560658 100644 --- a/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs +++ b/Src/Newtonsoft.Json/Utilities/ThreadSafeStore.cs @@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Utilities { if (creator == null) { - throw new ArgumentNullException("creator"); + throw new ArgumentNullException(nameof(creator)); } _creator = creator;