From 695bb8368fabd1c9a855ebb6ebaaf926b4be7678 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 6 Apr 2013 15:19:33 +1300 Subject: [PATCH] -Fixed build -Removed unused code --- .../Bson/BsonReaderTests.cs | 54 +-- .../Bson/BsonWriterTests.cs | 28 +- .../Converters/IsoDateTimeConverterTests.cs | 9 +- .../Converters/ObjectIdConverterTests.cs | 8 +- .../Converters/RegexConverterTests.cs | 6 +- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 2 +- .../JsonTextReaderTest.cs | 19 + Src/Newtonsoft.Json.Tests/Linq/JPathTests.cs | 4 +- .../Newtonsoft.Json.Tests.Portable40.csproj | 332 ++++++++++++++++++ .../Schema/JsonSchemaGeneratorTests.cs | 8 +- .../Serialization/DynamicTests.cs | 4 +- .../Serialization/JsonSerializerTest.cs | 12 +- .../Serialization/TypeNameHandlingTests.cs | 22 +- Src/Newtonsoft.Json.Tests/TestFixtureBase.cs | 42 +++ .../Utilities/ReflectionUtilsTests.cs | 8 +- .../Converters/KeyValuePairConverter.cs | 2 +- .../Converters/XmlNodeConverter.cs | 14 +- Src/Newtonsoft.Json/JsonTextReader.cs | 2 + Src/Newtonsoft.Json/Linq/JContainer.cs | 4 + Src/Newtonsoft.Json/Linq/JPath.cs | 4 +- .../Newtonsoft.Json.Net20.csproj | 1 - .../Newtonsoft.Json.Net35.csproj | 1 - .../Newtonsoft.Json.Net40.csproj | 1 - .../Newtonsoft.Json.Portable.csproj | 1 - .../Newtonsoft.Json.Portable40.csproj | 228 ++++++++++++ .../Newtonsoft.Json.WinRT.csproj | 1 - .../Newtonsoft.Json.WindowsPhone.csproj | 1 - Src/Newtonsoft.Json/Newtonsoft.Json.csproj | 1 - .../Schema/JsonSchemaGenerator.cs | 6 +- .../Serialization/DefaultContractResolver.cs | 10 +- .../Serialization/JsonArrayContract.cs | 20 +- .../Serialization/JsonContract.cs | 4 +- .../Serialization/JsonDictionaryContract.cs | 10 +- .../JsonISerializableContract.cs | 2 +- .../JsonSerializerInternalReader.cs | 4 +- .../Serialization/JsonTypeReflector.cs | 2 +- .../Utilities/CollectionUtils.cs | 91 +---- Src/Newtonsoft.Json/Utilities/ConvertUtils.cs | 2 +- .../Utilities/DateTimeUtils.cs | 7 - .../Utilities/JavaScriptUtils.cs | 5 - .../LateBoundReflectionDelegateFactory.cs | 2 +- Src/Newtonsoft.Json/Utilities/ListWrapper.cs | 189 ---------- .../Utilities/MiscellaneousUtils.cs | 58 --- .../Utilities/ReflectionUtils.cs | 78 ---- .../Utilities/ValidationUtils.cs | 20 -- 45 files changed, 755 insertions(+), 574 deletions(-) create mode 100644 Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable40.csproj create mode 100644 Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj delete mode 100644 Src/Newtonsoft.Json/Utilities/ListWrapper.cs diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs index 068489f0..e0246bca 100644 --- a/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs +++ b/Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs @@ -70,7 +70,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadSingleObject() { - byte[] data = MiscellaneousUtils.HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00"); + byte[] data = HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -97,7 +97,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadDouble() { - byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00"); + byte[] data = HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -121,7 +121,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadDouble_Decimal() { - byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00"); + byte[] data = HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -146,7 +146,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadValues() { - byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00"); + byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); reader.JsonNet35BinaryCompatibility = true; @@ -236,7 +236,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadObjectBsonFromSite() { - byte[] data = MiscellaneousUtils.HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); + byte[] data = HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -284,7 +284,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadArrayBsonFromSite() { - byte[] data = MiscellaneousUtils.HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); + byte[] data = HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -330,7 +330,7 @@ namespace Newtonsoft.Json.Tests.Bson "Could not convert string to integer: a. Path '[0]'.", () => { - byte[] data = MiscellaneousUtils.HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); + byte[] data = HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -354,7 +354,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadBytes() { - byte[] data = MiscellaneousUtils.HexToBytes("2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00"); + byte[] data = HexToBytes("2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc); @@ -395,7 +395,7 @@ namespace Newtonsoft.Json.Tests.Bson [Test] public void ReadOid() { - byte[] data = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); + byte[] data = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -409,7 +409,7 @@ namespace Newtonsoft.Json.Tests.Bson Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.Bytes, reader.TokenType); - CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"), (byte[])reader.Value); + CollectionAssert.AreEquivalent(HexToBytes("4ABBED9D1D8B0F0218000001"), (byte[])reader.Value); Assert.AreEqual(typeof(byte[]), reader.ValueType); Assert.IsTrue(reader.Read()); @@ -433,7 +433,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -447,7 +447,7 @@ namespace Newtonsoft.Json.Tests.Bson Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.Bytes, reader.TokenType); - CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"), (byte[])reader.Value); + CollectionAssert.AreEquivalent(HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"), (byte[])reader.Value); Assert.AreEqual(typeof(byte[]), reader.ValueType); Assert.IsTrue(reader.Read()); @@ -492,7 +492,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); BsonReader reader = new BsonReader(new MemoryStream(data)); reader.JsonNet35BinaryCompatibility = true; @@ -505,14 +505,14 @@ namespace Newtonsoft.Json.Tests.Bson o.WriteTo(writer); writer.Flush(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(hexdoc, bson); } [Test] public void OidAndBytesAreEqual() { - byte[] data1 = MiscellaneousUtils.HexToBytes( + byte[] data1 = HexToBytes( "82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); BsonReader reader1 = new BsonReader(new MemoryStream(data1)); @@ -521,7 +521,7 @@ namespace Newtonsoft.Json.Tests.Bson // oid JObject o1 = (JObject)JToken.ReadFrom(reader1); - byte[] data2 = MiscellaneousUtils.HexToBytes( + byte[] data2 = HexToBytes( "87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"); BsonReader reader2 = new BsonReader(new MemoryStream(data2)); @@ -538,7 +538,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "15-00-00-00-0B-72-65-67-65-78-00-74-65-73-74-00-67-69-6D-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -567,7 +567,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "1A-00-00-00-0D-63-6F-64-65-00-0B-00-00-00-49-20-61-6D-20-63-6F-64-65-21-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -596,7 +596,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "10-00-00-00-06-75-6E-64-65-66-69-6E-65-64-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -625,7 +625,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "13-00-00-00-12-6C-6F-6E-67-00-FF-FF-FF-FF-FF-FF-FF-7F-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -654,7 +654,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "1E-00-00-00-0C-6F-69-64-00-04-00-00-00-6F-69-64-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -701,7 +701,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "75-00-00-00-0F-63-6F-64-65-57-69-74-68-53-63-6F-70-65-00-61-00-00-00-35-00-00-00-66-6F-72-20-28-69-6E-74-20-69-20-3D-20-30-3B-20-69-20-3C-20-31-30-30-30-3B-20-69-2B-2B-29-0D-0A-7B-0D-0A-20-20-61-6C-65-72-74-28-61-72-67-31-29-3B-0D-0A-7D-00-24-00-00-00-02-61-72-67-31-00-15-00-00-00-4A-73-6F-6E-2E-4E-45-54-20-69-73-20-61-77-65-73-6F-6D-65-2E-00-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -768,7 +768,7 @@ namespace Newtonsoft.Json.Tests.Bson string bson = "4E-02-00-00-02-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-22-01-00-00-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-00"; - BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson))); + BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson))); StringBuilder largeStringBuilder = new StringBuilder(); for (int i = 0; i < 100; i++) @@ -803,7 +803,7 @@ namespace Newtonsoft.Json.Tests.Bson { string bson = "0C-00-00-00-02-00-01-00-00-00-00-00"; - BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson))); + BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson))); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.StartObject, reader.TokenType); @@ -842,7 +842,7 @@ namespace Newtonsoft.Json.Tests.Bson Assert.AreEqual("20-00-00-00-03-41-72-67-75-6D-65-6E-74-73-00-05-00-00-00-00-04-4C-69-73-74-00-05-00-00-00-00-00", bson); - BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson))); + BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson))); Assert.IsTrue(reader.Read()); Assert.AreEqual(JsonToken.StartObject, reader.TokenType); @@ -1155,7 +1155,7 @@ namespace Newtonsoft.Json.Tests.Bson { string hexdoc = "1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00"; - byte[] data = MiscellaneousUtils.HexToBytes(hexdoc); + byte[] data = HexToBytes(hexdoc); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); @@ -1376,7 +1376,7 @@ namespace Newtonsoft.Json.Tests.Bson { BigInteger i = BigInteger.Parse("1999999999999999999999999999999999999999999999999999999999990"); - byte[] data = MiscellaneousUtils.HexToBytes("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00"); + byte[] data = HexToBytes("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00"); MemoryStream ms = new MemoryStream(data); BsonReader reader = new BsonReader(ms); diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs index 159c3de9..2c3af63c 100644 --- a/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs @@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(1); writer.WriteEndObject(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00", bson); } @@ -109,7 +109,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc)); writer.WriteEnd(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-00-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson); } #endif @@ -124,7 +124,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(99.99d); writer.WriteEnd(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson); } @@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Tests.Bson ms.Seek(0, SeekOrigin.Begin); string expected = "20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00"; - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(expected, bson); } @@ -167,7 +167,7 @@ namespace Newtonsoft.Json.Tests.Bson ms.Seek(0, SeekOrigin.Begin); string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00"; - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(expected, bson); @@ -189,7 +189,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteStartObject(); writer.WritePropertyName("_id"); - writer.WriteValue(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF")); + writer.WriteValue(HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF")); writer.WritePropertyName("a"); writer.WriteStartArray(); @@ -213,7 +213,7 @@ namespace Newtonsoft.Json.Tests.Bson ms.Seek(0, SeekOrigin.Begin); string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00"; - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(expected, bson); } @@ -298,7 +298,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(largeString); writer.WriteEndObject(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("4E-02-00-00-02-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-22-01-00-00-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-00", bson); } @@ -388,7 +388,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(""); writer.WriteEndObject(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("0C-00-00-00-02-00-01-00-00-00-00-00", bson); } @@ -502,7 +502,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteObjectId(oid); writer.WriteEndObject(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("17-00-00-00-07-5F-6F-69-64-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-00", bson); ms.Seek(0, SeekOrigin.Begin); @@ -530,12 +530,12 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteStartObject(); writer.WritePropertyName("_id"); - writer.WriteObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001")); + writer.WriteObjectId(HexToBytes("4ABBED9D1D8B0F0218000001")); writer.WritePropertyName("test"); writer.WriteValue("1234£56"); writer.WriteEndObject(); - byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); + byte[] expected = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); CollectionAssert.AreEquivalent(expected, ms.ToArray()); } @@ -553,7 +553,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteRegex(string.Empty, null); writer.WriteEndObject(); - byte[] expected = MiscellaneousUtils.HexToBytes("1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00"); + byte[] expected = HexToBytes("1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00"); CollectionAssert.AreEquivalent(expected, ms.ToArray()); } @@ -712,7 +712,7 @@ namespace Newtonsoft.Json.Tests.Bson writer.WriteValue(i); writer.WriteEndObject(); - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00", bson); ms.Seek(0, SeekOrigin.Begin); diff --git a/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs index e3c5828b..48850f78 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/IsoDateTimeConverterTests.cs @@ -61,6 +61,13 @@ namespace Newtonsoft.Json.Tests.Converters Assert.AreEqual(DateTimeStyles.None, converter.DateTimeStyles); } + public static string GetUtcOffsetText(DateTime d) + { + TimeSpan utcOffset = d.GetUtcOffset(); + + return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture); + } + [Test] public void SerializeDateTime() { @@ -76,7 +83,7 @@ namespace Newtonsoft.Json.Tests.Converters d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Local); result = JsonConvert.SerializeObject(d, converter); - Assert.AreEqual(@"""2000-12-15T22:11:03.055" + d.GetUtcOffsetText() + @"""", result); + Assert.AreEqual(@"""2000-12-15T22:11:03.055" + GetUtcOffsetText(d) + @"""", result); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Converters/ObjectIdConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/ObjectIdConverterTests.cs index 1a9fd55b..ded76aca 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/ObjectIdConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/ObjectIdConverterTests.cs @@ -52,7 +52,7 @@ namespace Newtonsoft.Json.Tests.Converters { ObjectIdTestClass c = new ObjectIdTestClass { - Id = new BsonObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001")), + Id = new BsonObjectId(HexToBytes("4ABBED9D1D8B0F0218000001")), Test = "1234£56" }; @@ -63,7 +63,7 @@ namespace Newtonsoft.Json.Tests.Converters BsonWriter writer = new BsonWriter(ms); serializer.Serialize(writer, c); - byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); + byte[] expected = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); CollectionAssert.AreEquivalent(expected, ms.ToArray()); } @@ -71,14 +71,14 @@ namespace Newtonsoft.Json.Tests.Converters [Test] public void Deserialize() { - byte[] bson = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); + byte[] bson = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000"); JsonSerializer serializer = new JsonSerializer(); BsonReader reader = new BsonReader(new MemoryStream(bson)); ObjectIdTestClass c = serializer.Deserialize(reader); - CollectionAssert.AreEquivalent(c.Id.Value, MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001")); + CollectionAssert.AreEquivalent(c.Id.Value, HexToBytes("4ABBED9D1D8B0F0218000001")); Assert.AreEqual(c.Test, "1234£56"); } } diff --git a/Src/Newtonsoft.Json.Tests/Converters/RegexConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/RegexConverterTests.cs index 7d9ec30e..25ffcc54 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/RegexConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/RegexConverterTests.cs @@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Tests.Converters serializer.Serialize(writer, new RegexTestClass { Regex = regex }); string expected = "13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00"; - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(expected, bson); } @@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Tests.Converters [Test] public void DeserializeFromBson() { - MemoryStream ms = new MemoryStream(MiscellaneousUtils.HexToBytes("13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00")); + MemoryStream ms = new MemoryStream(HexToBytes("13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00")); BsonReader reader = new BsonReader(ms); JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new RegexConverter()); @@ -150,7 +150,7 @@ namespace Newtonsoft.Json.Tests.Converters serializer.Serialize(writer, new RegexTestClass { Regex = regex }); string expected = "14-00-00-00-0B-52-65-67-65-78-00-2F-00-69-6D-73-75-78-00-00"; - string bson = MiscellaneousUtils.BytesToHex(ms.ToArray()); + string bson = BytesToHex(ms.ToArray()); Assert.AreEqual(expected, bson); diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index b8f30e51..af4cf626 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -143,7 +143,7 @@ now brown cow?", '"', true); result = JavaScriptUtils.ToEscapedJavaScriptString(@"Fred's ""cat"".", '\'', true); Assert.AreEqual(result, @"'Fred\'s ""cat"".'"); - result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress"); + result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress", '"', true); Assert.AreEqual(result, @"""\u001farray( + ExceptionAssert.Throws( @"Index 1 outside the bounds of JConstructor.", () => { @@ -279,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Linq { JArray a = new JArray(1, 2, 3, 4, 5); - ExceptionAssert.Throws( + ExceptionAssert.Throws( "Index 1000 outside the bounds of JArray.", () => { diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable40.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable40.csproj new file mode 100644 index 00000000..fe4ed05e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable40.csproj @@ -0,0 +1,332 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3E6E2335-B079-4B5B-A65A-9D586914BCBB} + Library + Properties + Newtonsoft.Json.Tests + Newtonsoft.Json.Tests + + + + + + + + + + + 3.5 + + + v4.5 + false + + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + + true + full + false + bin\Debug\Portable\ + TRACE;DEBUG;PORTABLE40 + prompt + 4 + AllRules.ruleset + false + + + pdbonly + true + bin\Release\Portable\ + TRACE;PORTABLE40 + prompt + 4 + AllRules.ruleset + false + + + + + False + ..\Lib\NUnit\DotNet\nunit.framework.dll + + + + 3.5 + + + 3.5 + + + + 3.5 + + + 3.5 + + + + + 3.0 + + + + 3.0 + + + 3.5 + + + + 3.5 + + + + + 3.5 + + + + + + + + + + + + + + + + True + True + FileSystemEntityModel.edmx + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EntityModelCodeGenerator + FileSystemEntityModel.Designer.cs + + + + + Always + + + Always + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + {959f7f85-c98b-4876-971a-9036224578e4} + Newtonsoft.Json.Portable40 + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs index 9403a6e7..f8d21202 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs @@ -357,7 +357,7 @@ namespace Newtonsoft.Json.Tests.Schema IList properties = base.CreateProperties(type, memberSerialization); JsonPropertyCollection c = new JsonPropertyCollection(type); - CollectionUtils.AddRange(c, (IEnumerable)properties.Where(m => m.PropertyName != "Root")); + c.AddRange(properties.Where(m => m.PropertyName != "Root")); return c; } @@ -473,9 +473,9 @@ namespace Newtonsoft.Json.Tests.Schema JsonSchemaGenerator generator = new JsonSchemaGenerator(); generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName; generator.ContractResolver = new CamelCasePropertyNamesContractResolver() - { -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) - IgnoreSerializableAttribute = true + { +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) + IgnoreSerializableAttribute = true #endif }; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs index 5b0aaa66..c90b5a01 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs @@ -121,8 +121,8 @@ namespace Newtonsoft.Json.Tests.Serialization Console.WriteLine(json); - string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full); - string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full); + string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full, null); + string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full, null); Assert.AreEqual(@"{ ""$type"": """ + expandoObjectTypeName + @""", diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 22b6b773..a566da2a 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -2279,7 +2279,7 @@ Path '', line 1, position 2.", { ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) IgnoreSerializableAttribute = true #endif } @@ -2298,7 +2298,7 @@ Path '', line 1, position 2.", { ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) IgnoreSerializableAttribute = true #endif } @@ -2316,9 +2316,9 @@ Path '', line 1, position 2.", JsonConvert.DeserializeObject("{ReadTimeout:''}", new JsonSerializerSettings { ContractResolver = new DefaultContractResolver - { -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) - IgnoreSerializableAttribute = true + { +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) + IgnoreSerializableAttribute = true #endif } }); @@ -2336,7 +2336,7 @@ Path '', line 1, position 2.", { ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) IgnoreSerializableAttribute = true #endif } diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index 702f6fae..d7c6a081 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -165,7 +165,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteTypeNameForObjects() { - string employeeRef = ReflectionUtils.GetTypeName(typeof (EmployeeReference), FormatterAssemblyStyle.Simple); + string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null); EmployeeReference employee = new EmployeeReference(); @@ -185,7 +185,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void DeserializeTypeName() { - string employeeRef = ReflectionUtils.GetTypeName(typeof (EmployeeReference), FormatterAssemblyStyle.Simple); + string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null); string json = @"{ ""$id"": ""1"", @@ -207,7 +207,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void DeserializeTypeNameFromGacAssembly() { - string cookieRef = ReflectionUtils.GetTypeName(typeof (Cookie), FormatterAssemblyStyle.Simple); + string cookieRef = ReflectionUtils.GetTypeName(typeof (Cookie), FormatterAssemblyStyle.Simple, null); string json = @"{ ""$id"": ""1"", @@ -493,7 +493,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteObjectTypeNameForProperty() { - string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof (TypeNameProperty), FormatterAssemblyStyle.Simple); + string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof (TypeNameProperty), FormatterAssemblyStyle.Simple, null); TypeNameProperty typeNameProperty = new TypeNameProperty { @@ -527,7 +527,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void WriteListTypeNameForProperty() { - string listRef = ReflectionUtils.GetTypeName(typeof (List), FormatterAssemblyStyle.Simple); + string listRef = ReflectionUtils.GetTypeName(typeof (List), FormatterAssemblyStyle.Simple, null); TypeNameProperty typeNameProperty = new TypeNameProperty { @@ -709,9 +709,9 @@ namespace Newtonsoft.Json.Tests.Serialization string json = sw.ToString(); - string contentSubClassRef = ReflectionUtils.GetTypeName(typeof (ContentSubClass), FormatterAssemblyStyle.Simple); - string dictionaryRef = ReflectionUtils.GetTypeName(typeof (Dictionary>), FormatterAssemblyStyle.Simple); - string listRef = ReflectionUtils.GetTypeName(typeof (List), FormatterAssemblyStyle.Simple); + string contentSubClassRef = ReflectionUtils.GetTypeName(typeof (ContentSubClass), FormatterAssemblyStyle.Simple, null); + string dictionaryRef = ReflectionUtils.GetTypeName(typeof (Dictionary>), FormatterAssemblyStyle.Simple, null); + string listRef = ReflectionUtils.GetTypeName(typeof (List), FormatterAssemblyStyle.Simple, null); string expected = @"{ ""TestMember"": { @@ -816,7 +816,7 @@ namespace Newtonsoft.Json.Tests.Serialization TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple }); - string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple); + string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple, null); Assert.AreEqual(@"{ ""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"", @@ -867,7 +867,7 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void SerializingIEnumerableOfTShouldRetainGenericTypeInfo() { - string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable), FormatterAssemblyStyle.Simple); + string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable), FormatterAssemblyStyle.Simple, null); CustomEnumerable products = new CustomEnumerable(); @@ -951,7 +951,7 @@ namespace Newtonsoft.Json.Tests.Serialization string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings); - string carClassRef = ReflectionUtils.GetTypeName(typeof (Car), FormatterAssemblyStyle.Simple); + string carClassRef = ReflectionUtils.GetTypeName(typeof (Car), FormatterAssemblyStyle.Simple, null); Assert.AreEqual(output, @"{ ""$type"": """ + carClassRef + @""", diff --git a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs index 55fc3c75..ea8e2887 100644 --- a/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs +++ b/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs @@ -62,6 +62,48 @@ namespace Newtonsoft.Json.Tests return sw.ToString(); } + protected string BytesToHex(byte[] bytes) + { + return BytesToHex(bytes, false); + } + + protected string BytesToHex(byte[] bytes, bool removeDashes) + { + string hex = BitConverter.ToString(bytes); + if (removeDashes) + hex = hex.Replace("-", ""); + + return hex; + } + + protected byte[] HexToBytes(string hex) + { + string fixedHex = hex.Replace("-", string.Empty); + + // array to put the result in + byte[] bytes = new byte[fixedHex.Length / 2]; + // variable to determine shift of high/low nibble + int shift = 4; + // offset of the current byte in the array + int offset = 0; + // loop the characters in the string + foreach (char c in fixedHex) + { + // get character code in range 0-9, 17-22 + // the % 32 handles lower case characters + int b = (c - '0') % 32; + // correction for a-f + if (b > 9) b -= 7; + // store nibble (4 bits) in byte array + bytes[offset] |= (byte)(b << shift); + // toggle the shift variable between 0 and 4 + shift ^= 4; + // move to next byte + if (shift != 0) offset++; + } + return bytes; + } + #if !NETFX_CORE [SetUp] protected void TestSetup() diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs index 2bac182e..6e723b02 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs @@ -46,16 +46,16 @@ namespace Newtonsoft.Json.Tests.Utilities { string typeName; - typeName = ReflectionUtils.GetTypeName(typeof(IList), FormatterAssemblyStyle.Simple); + typeName = ReflectionUtils.GetTypeName(typeof(IList), FormatterAssemblyStyle.Simple, null); Assert.AreEqual("System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IDictionary, IList>), FormatterAssemblyStyle.Simple); + typeName = ReflectionUtils.GetTypeName(typeof(IDictionary, IList>), FormatterAssemblyStyle.Simple, null); Assert.AreEqual("System.Collections.Generic.IDictionary`2[[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib],[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib]], mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IList<>), FormatterAssemblyStyle.Simple); + typeName = ReflectionUtils.GetTypeName(typeof(IList<>), FormatterAssemblyStyle.Simple, null); Assert.AreEqual("System.Collections.Generic.IList`1, mscorlib", typeName); - typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), FormatterAssemblyStyle.Simple); + typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), FormatterAssemblyStyle.Simple, null); Assert.AreEqual("System.Collections.Generic.IDictionary`2, mscorlib", typeName); } } diff --git a/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs b/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs index 17f210ea..bb41ff27 100644 --- a/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs +++ b/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs @@ -116,7 +116,7 @@ namespace Newtonsoft.Json.Converters reader.Read(); } - return ReflectionUtils.CreateInstance(t, key, value); + return Activator.CreateInstance(t, key, value); } /// diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 34a26f0d..38878409 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -195,11 +195,6 @@ namespace Newtonsoft.Json.Converters get { return _node.NodeType; } } - public string Name - { - get { return _node.Name; } - } - public string LocalName { get { return _node.LocalName; } @@ -263,11 +258,6 @@ namespace Newtonsoft.Json.Converters return newChild; } - public string Prefix - { - get { return _node.Prefix; } - } - public string NamespaceUri { get { return _node.NamespaceURI; } @@ -1308,7 +1298,7 @@ namespace Newtonsoft.Json.Converters if (count == 1 && WriteArrayAttribute) { - IXmlElement arrayElement = nestedArrayElement.ChildNodes.CastValid().Single(n => n.LocalName == propertyName); + IXmlElement arrayElement = nestedArrayElement.ChildNodes.OfType().Single(n => n.LocalName == propertyName); AddJsonArrayAttribute(arrayElement, document); } } @@ -1489,7 +1479,7 @@ namespace Newtonsoft.Json.Converters if (count == 1 && WriteArrayAttribute) { - IXmlElement arrayElement = currentNode.ChildNodes.CastValid().Single(n => n.LocalName == propertyName); + IXmlElement arrayElement = currentNode.ChildNodes.OfType().Single(n => n.LocalName == propertyName); AddJsonArrayAttribute(arrayElement, document); } } diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index 29c98a3d..db4fb92d 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -81,10 +81,12 @@ namespace Newtonsoft.Json _chars = new char[4097]; } +#if DEBUG internal void SetCharBuffer(char[] chars) { _chars = chars; } +#endif private StringBuffer GetBuffer() { diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index c3ff182a..5cce3789 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -97,7 +97,9 @@ namespace Newtonsoft.Json.Linq protected abstract IList ChildrenTokens { get; } private object _syncRoot; +#if !(PORTABLE40) private bool _busy; +#endif internal JContainer() { @@ -116,8 +118,10 @@ namespace Newtonsoft.Json.Linq internal void CheckReentrancy() { +#if !(PORTABLE40) if (_busy) throw new InvalidOperationException("Cannot change {0} during a collection change event.".FormatWith(CultureInfo.InvariantCulture, GetType())); +#endif } internal virtual IList CreateChildrenCollection() diff --git a/Src/Newtonsoft.Json/Linq/JPath.cs b/Src/Newtonsoft.Json/Linq/JPath.cs index 572144fb..bd8eb160 100644 --- a/Src/Newtonsoft.Json/Linq/JPath.cs +++ b/Src/Newtonsoft.Json/Linq/JPath.cs @@ -173,7 +173,7 @@ namespace Newtonsoft.Json.Linq if (a.Count <= index) { if (errorWhenNoMatch) - throw new IndexOutOfRangeException("Index {0} outside the bounds of JArray.".FormatWith(CultureInfo.InvariantCulture, index)); + throw new JsonException("Index {0} outside the bounds of JArray.".FormatWith(CultureInfo.InvariantCulture, index)); return null; } @@ -185,7 +185,7 @@ namespace Newtonsoft.Json.Linq if (c.Count <= index) { if (errorWhenNoMatch) - throw new IndexOutOfRangeException("Index {0} outside the bounds of JConstructor.".FormatWith(CultureInfo.InvariantCulture, index)); + throw new JsonException("Index {0} outside the bounds of JConstructor.".FormatWith(CultureInfo.InvariantCulture, index)); return null; } diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj index 1e5b31f6..4e54d7e7 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -232,7 +232,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 05d4c9b9..1acce3ec 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -246,7 +246,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj index 3d98fa84..0c007da1 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net40.csproj @@ -244,7 +244,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj index 63baf38c..b9922e63 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -204,7 +204,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj new file mode 100644 index 00000000..9fec121c --- /dev/null +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable40.csproj @@ -0,0 +1,228 @@ + + + + Debug + AnyCPU + {959F7F85-C98B-4876-971A-9036224578E4} + Library + Properties + Newtonsoft.Json + Newtonsoft.Json + v4.0 + Profile2 + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + + + true + full + false + bin\Debug\Portable\ + TRACE;DEBUG;CODE_ANALYSIS;PORTABLE40 + prompt + 4 + true + Newtonsoft.Json.ruleset + + + pdbonly + true + bin\Release\Portable\ + TRACE;CODE_ANALYSIS;PORTABLE40 + prompt + 4 + bin\Release\Portable\Newtonsoft.Json.xml + true + Newtonsoft.Json.ruleset + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj index 92ccbd5a..ac42ce83 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.WinRT.csproj @@ -268,7 +268,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj index d260d720..2adffc9a 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.WindowsPhone.csproj @@ -193,7 +193,6 @@ - diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 6ab40ad8..e86f25db 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -200,7 +200,6 @@ - diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs index f48b5f6a..e462462d 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs @@ -327,14 +327,14 @@ namespace Newtonsoft.Json.Schema } } break; -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) case JsonContractType.Serializable: CurrentSchema.Type = AddNullType(JsonSchemaType.Object, valueRequired); CurrentSchema.Id = GetTypeId(type, false); GenerateISerializableContract(type, (JsonISerializableContract) contract); break; #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE40) case JsonContractType.Dynamic: #endif case JsonContractType.Linq: @@ -386,7 +386,7 @@ namespace Newtonsoft.Json.Schema CurrentSchema.AllowAdditionalProperties = false; } -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) private void GenerateISerializableContract(Type type, JsonISerializableContract contract) { CurrentSchema.AllowAdditionalProperties = true; diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index f09e2878..05258632 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -133,7 +133,7 @@ namespace Newtonsoft.Json.Serialization get { return JsonTypeReflector.DynamicCodeGeneration; } } -#if !(NETFX_CORE || PORTABLE40 || PORTABLE) +#if !(NETFX_CORE || PORTABLE) /// /// Gets or sets the default members search flags. /// @@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Serialization /// public bool SerializeCompilerGeneratedMembers { get; set; } -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) /// /// Gets or sets a value indicating whether to ignore the interface when serializing and deserializing types. /// @@ -191,7 +191,7 @@ namespace Newtonsoft.Json.Serialization #if !NETFX_CORE DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.Instance; #endif -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) IgnoreSerializableAttribute = true; #endif @@ -256,7 +256,7 @@ namespace Newtonsoft.Json.Serialization protected virtual List GetSerializableMembers(Type objectType) { bool ignoreSerializableAttribute; -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) ignoreSerializableAttribute = IgnoreSerializableAttribute; #else ignoreSerializableAttribute = true; @@ -350,7 +350,7 @@ namespace Newtonsoft.Json.Serialization InitializeContract(contract); bool ignoreSerializableAttribute; -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) ignoreSerializableAttribute = IgnoreSerializableAttribute; #else ignoreSerializableAttribute = true; diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index f0631c22..8031aa14 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -83,7 +83,7 @@ namespace Newtonsoft.Json.Serialization { CollectionItemType = ReflectionUtils.GetCollectionItemType(UnderlyingType); IsReadOnlyOrFixedSize = true; - _genericCollectionDefinitionType = ReflectionUtils.MakeGenericType(typeof (List<>), CollectionItemType); + _genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType); canDeserialize = true; IsMultidimensionalArray = (UnderlyingType.IsArray && UnderlyingType.GetArrayRank() > 1); @@ -108,11 +108,11 @@ namespace Newtonsoft.Json.Serialization if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ICollection<>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof(IList<>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + CreatedType = typeof(List<>).MakeGenericType(CollectionItemType); #if !(NET20 || NET35 || PORTABLE40) if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof(ISet<>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(HashSet<>), CollectionItemType); + CreatedType = typeof(HashSet<>).MakeGenericType(CollectionItemType); #endif ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType); @@ -126,9 +126,9 @@ namespace Newtonsoft.Json.Serialization if (ReflectionUtils.IsGenericDefinition(underlyingType, typeof (IReadOnlyCollection<>)) || ReflectionUtils.IsGenericDefinition(underlyingType, typeof (IReadOnlyList<>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(ReadOnlyCollection<>), CollectionItemType); + CreatedType = typeof(ReadOnlyCollection<>).MakeGenericType(CollectionItemType); - _genericCollectionDefinitionType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + _genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType); ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, CollectionItemType); IsReadOnlyOrFixedSize = true; canDeserialize = (ParametrizedConstructor != null); @@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Serialization CollectionItemType = tempCollectionType.GetGenericArguments()[0]; if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IEnumerable<>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + CreatedType = typeof(List<>).MakeGenericType(CollectionItemType); ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType); @@ -153,7 +153,7 @@ namespace Newtonsoft.Json.Serialization } else { - _genericCollectionDefinitionType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + _genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType); IsReadOnlyOrFixedSize = true; ShouldCreateWrapper = true; @@ -188,13 +188,13 @@ namespace Newtonsoft.Json.Serialization { if (_genericWrapperCreator == null) { - _genericWrapperType = ReflectionUtils.MakeGenericType(typeof (CollectionWrapper<>), CollectionItemType); + _genericWrapperType = typeof(CollectionWrapper<>).MakeGenericType(CollectionItemType); Type constructorArgument; if (ReflectionUtils.InheritsGenericDefinition(_genericCollectionDefinitionType, typeof(List<>)) || _genericCollectionDefinitionType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) - constructorArgument = ReflectionUtils.MakeGenericType(typeof(ICollection<>), CollectionItemType); + constructorArgument = typeof(ICollection<>).MakeGenericType(CollectionItemType); else constructorArgument = _genericCollectionDefinitionType; @@ -211,7 +211,7 @@ namespace Newtonsoft.Json.Serialization { // multidimensional array will also have array instances in it Type collectionItemType = (IsMultidimensionalArray) ? typeof (object) : CollectionItemType; - Type temporaryListType = ReflectionUtils.MakeGenericType(typeof(List<>), collectionItemType); + Type temporaryListType = typeof(List<>).MakeGenericType(collectionItemType); _genericTemporaryCollectionCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor(temporaryListType); } diff --git a/Src/Newtonsoft.Json/Serialization/JsonContract.cs b/Src/Newtonsoft.Json/Serialization/JsonContract.cs index edb91e07..a9bf1963 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonContract.cs @@ -39,10 +39,10 @@ namespace Newtonsoft.Json.Serialization Primitive, String, Dictionary, -#if !(NET35 || NET20) +#if !(NET35 || NET20 || PORTABLE40) Dynamic, #endif -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) Serializable, #endif Linq diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index 6c6ccae0..f6e5978d 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -88,7 +88,7 @@ namespace Newtonsoft.Json.Serialization valueType = _genericCollectionDefinitionType.GetGenericArguments()[1]; if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IDictionary<,>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(Dictionary<,>), keyType, valueType); + CreatedType = typeof(Dictionary<,>).MakeGenericType(keyType, valueType); } #if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE40) else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IReadOnlyDictionary<,>), out _genericCollectionDefinitionType)) @@ -97,7 +97,7 @@ namespace Newtonsoft.Json.Serialization valueType = _genericCollectionDefinitionType.GetGenericArguments()[1]; if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IReadOnlyDictionary<,>))) - CreatedType = ReflectionUtils.MakeGenericType(typeof(ReadOnlyDictionary<,>), keyType, valueType); + CreatedType = typeof(ReadOnlyDictionary<,>).MakeGenericType(keyType, valueType); IsReadOnlyOrFixedSize = true; } @@ -111,7 +111,7 @@ namespace Newtonsoft.Json.Serialization } if (keyType != null && valueType != null) - ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, ReflectionUtils.MakeGenericType(typeof(KeyValuePair<,>), keyType, valueType)); + ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, typeof(KeyValuePair<,>).MakeGenericType(keyType, valueType)); ShouldCreateWrapper = !typeof (IDictionary).IsAssignableFrom(CreatedType); @@ -138,7 +138,7 @@ namespace Newtonsoft.Json.Serialization { if (_genericWrapperCreator == null) { - _genericWrapperType = ReflectionUtils.MakeGenericType(typeof(DictionaryWrapper<,>), DictionaryKeyType, DictionaryValueType); + _genericWrapperType = typeof(DictionaryWrapper<,>).MakeGenericType(DictionaryKeyType, DictionaryValueType); ConstructorInfo genericWrapperConstructor = _genericWrapperType.GetConstructor(new[] { _genericCollectionDefinitionType }); _genericWrapperCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall(genericWrapperConstructor); @@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Serialization { if (_genericTemporaryDictionaryCreator == null) { - Type temporaryDictionaryType = ReflectionUtils.MakeGenericType(typeof (Dictionary<,>), DictionaryKeyType, DictionaryValueType); + Type temporaryDictionaryType = typeof(Dictionary<,>).MakeGenericType(DictionaryKeyType, DictionaryValueType); _genericTemporaryDictionaryCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateDefaultConstructor(temporaryDictionaryType); } diff --git a/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs b/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs index d99a5f8b..980d2dc0 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) using System; namespace Newtonsoft.Json.Serialization diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index d27f27ce..a31dc6ba 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -301,10 +301,10 @@ namespace Newtonsoft.Json.Serialization { case JsonContractType.Object: case JsonContractType.Dictionary: -#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) case JsonContractType.Serializable: #endif -#if !(NET35 || NET20) +#if !(NET35 || NET20 || PORTABLE40) case JsonContractType.Dynamic: #endif return @"JSON object (e.g. {""name"":""value""})"; diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index 8ab59fa7..33f16b46 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -215,7 +215,7 @@ namespace Newtonsoft.Json.Serialization Type converterType = GetTypeConverterType(type); if (converterType != null) - return (TypeConverter)ReflectionUtils.CreateInstance(converterType); + return (TypeConverter)Activator.CreateInstance(converterType); return null; #endif diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index d9a9c8d4..ce5dbad6 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -41,13 +41,6 @@ namespace Newtonsoft.Json.Utilities { internal static class CollectionUtils { - public static IEnumerable CastValid(this IEnumerable enumerable) - { - ValidationUtils.ArgumentNotNull(enumerable, "enumerable"); - - return enumerable.Cast().Where(o => o is T).Cast(); - } - /// /// Determines whether the collection is null or empty. /// @@ -83,20 +76,15 @@ namespace Newtonsoft.Json.Utilities } } - public static void AddRange(this IList initial, IEnumerable collection) +#if (NET20 || NET35 || SILVERLIGHT || PORTABLE40) + public static void AddRange(this IList initial, IEnumerable collection) { ValidationUtils.ArgumentNotNull(initial, "initial"); - ListWrapper wrapper = new ListWrapper(initial); - wrapper.AddRange(collection.Cast()); - } - - public static IList CreateGenericList(Type listType) - { - ValidationUtils.ArgumentNotNull(listType, "listType"); - - return (IList)ReflectionUtils.CreateGeneric(typeof(List<>), listType); + // because earlier versions of .NET didn't support covariant generics + initial.AddRange(collection.Cast()); } +#endif public static bool IsDictionaryType(Type type) { @@ -116,7 +104,7 @@ namespace Newtonsoft.Json.Utilities public static ConstructorInfo ResolveEnumableCollectionConstructor(Type collectionType, Type collectionItemType) { - Type genericEnumerable = ReflectionUtils.MakeGenericType(typeof(IEnumerable<>), collectionItemType); + Type genericEnumerable = typeof(IEnumerable<>).MakeGenericType(collectionItemType); foreach (ConstructorInfo constructor in collectionType.GetConstructors(BindingFlags.Public | BindingFlags.Instance)) { @@ -132,73 +120,6 @@ namespace Newtonsoft.Json.Utilities return null; } - public static IWrappedCollection CreateCollectionWrapper(object list) - { - ValidationUtils.ArgumentNotNull(list, "list"); - - Type collectionDefinition; - if (ReflectionUtils.ImplementsGenericDefinition(list.GetType(), typeof(ICollection<>), out collectionDefinition)) - { - Type collectionItemType = ReflectionUtils.GetCollectionItemType(collectionDefinition); - - // Activator.CreateInstance throws AmbiguousMatchException. Manually invoke constructor - Func, object> instanceCreator = (t, a) => - { - ConstructorInfo c = t.GetConstructor(new[] { collectionDefinition }); - return c.Invoke(new[] { list }); - }; - - return (IWrappedCollection)ReflectionUtils.CreateGeneric(typeof(CollectionWrapper<>), new[] { collectionItemType }, instanceCreator, list); - } - else if (list is IList) - { - return new CollectionWrapper((IList)list); - } - else - { - throw new ArgumentException("Can not create ListWrapper for type {0}.".FormatWith(CultureInfo.InvariantCulture, list.GetType()), "list"); - } - } - - public static IWrappedDictionary CreateDictionaryWrapper(object dictionary) - { - ValidationUtils.ArgumentNotNull(dictionary, "dictionary"); - - Type dictionaryDefinition; - if (ReflectionUtils.ImplementsGenericDefinition(dictionary.GetType(), typeof(IDictionary<,>), out dictionaryDefinition)) - { - Type dictionaryKeyType = ReflectionUtils.GetDictionaryKeyType(dictionaryDefinition); - Type dictionaryValueType = ReflectionUtils.GetDictionaryValueType(dictionaryDefinition); - - // Activator.CreateInstance throws AmbiguousMatchException. Manually invoke constructor - Func, object> instanceCreator = (t, a) => - { - ConstructorInfo c = t.GetConstructor(new[] { dictionaryDefinition }); - return c.Invoke(new[] { dictionary }); - }; - - return (IWrappedDictionary)ReflectionUtils.CreateGeneric(typeof(DictionaryWrapper<,>), new[] { dictionaryKeyType, dictionaryValueType }, instanceCreator, dictionary); - } - else if (dictionary is IDictionary) - { - return new DictionaryWrapper((IDictionary)dictionary); - } - else - { - throw new ArgumentException("Can not create DictionaryWrapper for type {0}.".FormatWith(CultureInfo.InvariantCulture, dictionary.GetType()), "dictionary"); - } - } - - public static Array ToArray(Array initial, Type type) - { - if (type == null) - throw new ArgumentNullException("type"); - - Array destinationArray = Array.CreateInstance(type, initial.Length); - Array.Copy(initial, 0, destinationArray, 0, initial.Length); - return destinationArray; - } - public static bool AddDistinct(this IList list, T value) { return list.AddDistinct(value, EqualityComparer.Default); diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index 5f77be20..61d43bf8 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -189,7 +189,7 @@ namespace Newtonsoft.Json.Utilities Type nonNullable = Nullable.GetUnderlyingType(t); if (nonNullable.IsEnum()) { - Type nullableUnderlyingType = ReflectionUtils.MakeGenericType(typeof (Nullable<>), Enum.GetUnderlyingType(nonNullable)); + Type nullableUnderlyingType = typeof(Nullable<>).MakeGenericType(Enum.GetUnderlyingType(nonNullable)); return GetTypeCode(nullableUnderlyingType); } } diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs index 03b19c96..4d211d96 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs @@ -31,13 +31,6 @@ namespace Newtonsoft.Json.Utilities { internal static class DateTimeUtils { - public static string GetUtcOffsetText(this DateTime d) - { - TimeSpan utcOffset = d.GetUtcOffset(); - - return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture); - } - public static TimeSpan GetUtcOffset(this DateTime d) { #if NET20 diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index 4247882f..17333ab9 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -189,11 +189,6 @@ namespace Newtonsoft.Json.Utilities writer.Write(delimiter); } - public static string ToEscapedJavaScriptString(string value) - { - return ToEscapedJavaScriptString(value, '"', true); - } - public static string ToEscapedJavaScriptString(string value, char delimiter, bool appendDelimiters) { using (StringWriter w = StringUtils.CreateStringWriter(StringUtils.GetLength(value) ?? 16)) diff --git a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs index 0fd1c3e1..c2ba265e 100644 --- a/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/LateBoundReflectionDelegateFactory.cs @@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Utilities ValidationUtils.ArgumentNotNull(type, "type"); if (type.IsValueType()) - return () => (T)ReflectionUtils.CreateInstance(type); + return () => (T)Activator.CreateInstance(type); ConstructorInfo constructorInfo = ReflectionUtils.GetDefaultConstructor(type, true); diff --git a/Src/Newtonsoft.Json/Utilities/ListWrapper.cs b/Src/Newtonsoft.Json/Utilities/ListWrapper.cs deleted file mode 100644 index b21b81cc..00000000 --- a/Src/Newtonsoft.Json/Utilities/ListWrapper.cs +++ /dev/null @@ -1,189 +0,0 @@ -#region License -// Copyright (c) 2007 James Newton-King -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -#endregion - -using System.Collections; -using System.Collections.Generic; - -namespace Newtonsoft.Json.Utilities -{ - internal interface IWrappedList : IList - { - object UnderlyingList { get; } - } - - internal class ListWrapper : CollectionWrapper, IList, IWrappedList - { - private readonly IList _genericList; - - public ListWrapper(IList list) - : base(list) - { - ValidationUtils.ArgumentNotNull(list, "list"); - - if (list is IList) - _genericList = (IList) list; - } - - public ListWrapper(IList list) - : base(list) - { - ValidationUtils.ArgumentNotNull(list, "list"); - - _genericList = list; - } - - public int IndexOf(T item) - { - if (_genericList != null) - return _genericList.IndexOf(item); - else - return ((IList)this).IndexOf(item); - } - - public void Insert(int index, T item) - { - if (_genericList != null) - _genericList.Insert(index, item); - else - ((IList)this).Insert(index, item); - } - - public void RemoveAt(int index) - { - if (_genericList != null) - _genericList.RemoveAt(index); - else - ((IList)this).RemoveAt(index); - } - - public T this[int index] - { - get - { - if (_genericList != null) - return _genericList[index]; - else - return (T)((IList)this)[index]; - } - set - { - if (_genericList != null) - _genericList[index] = value; - else - ((IList)this)[index] = value; - } - } - - public override void Add(T item) - { - if (_genericList != null) - _genericList.Add(item); - else - base.Add(item); - } - - public override void Clear() - { - if (_genericList != null) - _genericList.Clear(); - else - base.Clear(); - } - - public override bool Contains(T item) - { - if (_genericList != null) - return _genericList.Contains(item); - else - return base.Contains(item); - } - - public override void CopyTo(T[] array, int arrayIndex) - { - if (_genericList != null) - _genericList.CopyTo(array, arrayIndex); - else - base.CopyTo(array, arrayIndex); - } - - public override int Count - { - get - { - if (_genericList != null) - return _genericList.Count; - else - return base.Count; - } - } - - public override bool IsReadOnly - { - get - { - if (_genericList != null) - return _genericList.IsReadOnly; - else - return base.IsReadOnly; - } - } - - public override bool Remove(T item) - { - if (_genericList != null) - { - return _genericList.Remove(item); - } - else - { - bool contains = base.Contains(item); - - if (contains) - base.Remove(item); - - return contains; - } - } - - public override IEnumerator GetEnumerator() - { - if (_genericList != null) - return _genericList.GetEnumerator(); - - return base.GetEnumerator(); - } - - public object UnderlyingList - { - get - { - if (_genericList != null) - return _genericList; - else - return UnderlyingCollection; - } - } - } -} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs index dd55f35b..a6fd8fc8 100644 --- a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs @@ -68,22 +68,6 @@ namespace Newtonsoft.Json.Utilities return new ArgumentOutOfRangeException(paramName, newMessage); } - public static bool TryAction(Creator creator, out T output) - { - ValidationUtils.ArgumentNotNull(creator, "creator"); - - try - { - output = creator(); - return true; - } - catch - { - output = default(T); - return false; - } - } - public static string ToString(object value) { if (value == null) @@ -92,48 +76,6 @@ namespace Newtonsoft.Json.Utilities return (value is string) ? @"""" + value.ToString() + @"""" : value.ToString(); } - public static byte[] HexToBytes(string hex) - { - string fixedHex = hex.Replace("-", string.Empty); - - // array to put the result in - byte[] bytes = new byte[fixedHex.Length / 2]; - // variable to determine shift of high/low nibble - int shift = 4; - // offset of the current byte in the array - int offset = 0; - // loop the characters in the string - foreach (char c in fixedHex) - { - // get character code in range 0-9, 17-22 - // the % 32 handles lower case characters - int b = (c - '0') % 32; - // correction for a-f - if (b > 9) b -= 7; - // store nibble (4 bits) in byte array - bytes[offset] |= (byte)(b << shift); - // toggle the shift variable between 0 and 4 - shift ^= 4; - // move to next byte - if (shift != 0) offset++; - } - return bytes; - } - - public static string BytesToHex(byte[] bytes) - { - return BytesToHex(bytes, false); - } - - public static string BytesToHex(byte[] bytes, bool removeDashes) - { - string hex = BitConverter.ToString(bytes); - if (removeDashes) - hex = hex.Replace("-", ""); - - return hex; - } - public static int ByteArrayCompare(byte[] a1, byte[] a2) { int lengthCompare = a1.Length.CompareTo(a2.Length); diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index cd7dd980..a198ee43 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -114,11 +114,6 @@ namespace Newtonsoft.Json.Utilities return (v != null) ? v.GetType() : null; } - public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat) - { - return GetTypeName(t, assemblyFormat, null); - } - public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder) { string fullyQualifiedTypeName; @@ -191,24 +186,6 @@ namespace Newtonsoft.Json.Utilities return builder.ToString(); } - public static bool IsInstantiatableType(Type t) - { - ValidationUtils.ArgumentNotNull(t, "t"); - - if (t.IsAbstract() || t.IsInterface() || t.IsArray || t.IsGenericTypeDefinition() || t == typeof(void)) - return false; - - if (!HasDefaultConstructor(t)) - return false; - - return true; - } - - public static bool HasDefaultConstructor(Type t) - { - return HasDefaultConstructor(t, false); - } - public static bool HasDefaultConstructor(Type t, bool nonPublic) { ValidationUtils.ArgumentNotNull(t, "t"); @@ -410,24 +387,6 @@ namespace Newtonsoft.Json.Utilities } } - public static Type GetDictionaryValueType(Type dictionaryType) - { - Type keyType; - Type valueType; - GetDictionaryKeyValueTypes(dictionaryType, out keyType, out valueType); - - return valueType; - } - - public static Type GetDictionaryKeyType(Type dictionaryType) - { - Type keyType; - Type valueType; - GetDictionaryKeyValueTypes(dictionaryType, out keyType, out valueType); - - return keyType; - } - /// /// Gets the member's underlying type. /// @@ -727,43 +686,6 @@ namespace Newtonsoft.Json.Utilities } #endif - public static Type MakeGenericType(Type genericTypeDefinition, params Type[] innerTypes) - { - ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition"); - ValidationUtils.ArgumentNotNullOrEmpty(innerTypes, "innerTypes"); - ValidationUtils.ArgumentConditionTrue(genericTypeDefinition.IsGenericTypeDefinition(), "genericTypeDefinition", "Type {0} is not a generic type definition.".FormatWith(CultureInfo.InvariantCulture, genericTypeDefinition)); - - return genericTypeDefinition.MakeGenericType(innerTypes); - } - - public static object CreateGeneric(Type genericTypeDefinition, Type innerType, params object[] args) - { - return CreateGeneric(genericTypeDefinition, new[] { innerType }, args); - } - - public static object CreateGeneric(Type genericTypeDefinition, IList innerTypes, params object[] args) - { - return CreateGeneric(genericTypeDefinition, innerTypes, (t, a) => CreateInstance(t, a.ToArray()), args); - } - - public static object CreateGeneric(Type genericTypeDefinition, IList innerTypes, Func, object> instanceCreator, params object[] args) - { - ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition"); - ValidationUtils.ArgumentNotNullOrEmpty(innerTypes, "innerTypes"); - ValidationUtils.ArgumentNotNull(instanceCreator, "createInstance"); - - Type specificType = MakeGenericType(genericTypeDefinition, innerTypes.ToArray()); - - return instanceCreator(specificType, args); - } - - public static object CreateInstance(Type type, params object[] args) - { - ValidationUtils.ArgumentNotNull(type, "type"); - - return Activator.CreateInstance(type, args); - } - public static void SplitFullyQualifiedTypeName(string fullyQualifiedTypeName, out string typeName, out string assemblyName) { int? assemblyDelimiterIndex = GetAssemblyDelimiterIndex(fullyQualifiedTypeName); diff --git a/Src/Newtonsoft.Json/Utilities/ValidationUtils.cs b/Src/Newtonsoft.Json/Utilities/ValidationUtils.cs index 3f01824c..9b187af9 100644 --- a/Src/Newtonsoft.Json/Utilities/ValidationUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ValidationUtils.cs @@ -50,30 +50,10 @@ namespace Newtonsoft.Json.Utilities throw new ArgumentException("Type {0} is not an Enum.".FormatWith(CultureInfo.InvariantCulture, enumType), parameterName); } - public static void ArgumentNotNullOrEmpty(ICollection collection, string parameterName) - { - ArgumentNotNullOrEmpty(collection, parameterName, "Collection '{0}' cannot be empty.".FormatWith(CultureInfo.InvariantCulture, parameterName)); - } - - public static void ArgumentNotNullOrEmpty(ICollection collection, string parameterName, string message) - { - if (collection == null) - throw new ArgumentNullException(parameterName); - - if (collection.Count == 0) - throw new ArgumentException(message, parameterName); - } - public static void ArgumentNotNull(object value, string parameterName) { if (value == null) throw new ArgumentNullException(parameterName); } - - public static void ArgumentConditionTrue(bool condition, string parameterName, string message) - { - if (!condition) - throw new ArgumentException(message, parameterName); - } } } \ No newline at end of file