From 10256fcf6872bc9f448a012edf4e02048a8a6e03 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 18 Apr 2012 21:02:34 +1200 Subject: [PATCH] -Added Portable Class Library build --- Build/build.ps1 | 1 + Src/Newtonsoft.Json.Portable.sln | 32 ++ .../Converters/BinaryConverterTests.cs | 8 +- .../Converters/DataSetConverterTests.cs | 2 +- .../Converters/DataTableConverterTests.cs | 2 +- .../Converters/ExpandoObjectConverterTests.cs | 2 +- .../Converters/XmlNodeConverterTest.cs | 2 +- Src/Newtonsoft.Json.Tests/JsonConvertTest.cs | 4 +- .../Linq/ComponentModel/BindingTests.cs | 2 +- .../JPropertyDescriptorTests.cs | 2 +- .../Linq/DynamicTests.cs | 2 +- Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs | 2 +- .../Linq/JObjectTests.cs | 10 +- .../Linq/JPropertyTests.cs | 2 +- Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs | 2 +- Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs | 2 +- .../Linq/LinqToJsonTest.cs | 2 +- .../Newtonsoft.Json.Tests.Portable.csproj | 326 ++++++++++++++++++ Src/Newtonsoft.Json.Tests/PerformanceTests.cs | 6 +- .../Properties/AssemblyInfo.cs | 2 +- .../Schema/ExtensionsTests.cs | 4 +- .../Schema/JsonSchemaGeneratorTests.cs | 14 +- ...lCasePropertyNamesContractResolverTests.cs | 2 +- .../Serialization/DynamicTests.cs | 2 +- .../EntitiesSerializationTests.cs | 2 +- .../Serialization/JsonSerializerTest.cs | 77 +++-- .../Serialization/TypeNameHandlingTests.cs | 8 +- .../Serialization/WebApiIntegrationTests.cs | 10 +- .../TestObjects/ConverableMembers.cs | 2 +- .../DynamicReflectionDelegateFactoryTests.cs | 2 +- .../Utilities/ReflectionUtilsTests.cs | 6 +- Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs | 2 +- Src/Newtonsoft.Json/Bson/BsonReader.cs | 2 +- Src/Newtonsoft.Json/Bson/BsonWriter.cs | 2 +- .../Converters/BinaryConverter.cs | 27 +- .../Converters/DataSetConverter.cs | 2 +- .../Converters/DataTableConverter.cs | 2 +- .../Converters/EntityKeyMemberConverter.cs | 2 +- .../Converters/ExpandoObjectConverter.cs | 2 +- .../Converters/XmlNodeConverter.cs | 2 +- Src/Newtonsoft.Json/FormatterAssemblyStyle.cs | 2 +- Src/Newtonsoft.Json/JsonConvert.cs | 20 +- Src/Newtonsoft.Json/JsonReaderException.cs | 4 +- .../JsonSerializationException.cs | 4 +- Src/Newtonsoft.Json/JsonTextReader.cs | 2 +- Src/Newtonsoft.Json/JsonTextWriter.cs | 2 +- Src/Newtonsoft.Json/JsonWriter.cs | 2 +- Src/Newtonsoft.Json/JsonWriterException.cs | 4 +- Src/Newtonsoft.Json/Linq/IJEnumerable.cs | 2 +- Src/Newtonsoft.Json/Linq/JContainer.cs | 39 ++- Src/Newtonsoft.Json/Linq/JObject.cs | 24 +- .../Linq/JPropertyDescriptor.cs | 2 +- Src/Newtonsoft.Json/Linq/JToken.cs | 10 +- Src/Newtonsoft.Json/Linq/JTokenWriter.cs | 2 +- Src/Newtonsoft.Json/Linq/JValue.cs | 8 +- .../Newtonsoft.Json.Portable.csproj | 212 ++++++++++++ .../Properties/AssemblyInfo.cs | 7 +- .../Schema/JsonSchemaException.cs | 4 +- .../Schema/JsonSchemaGenerator.cs | 10 +- .../Serialization/CachedAttributeGetter.cs | 2 +- .../Serialization/DefaultContractResolver.cs | 46 +-- .../DefaultSerializationBinder.cs | 2 +- .../Serialization/DynamicValueProvider.cs | 2 +- .../Serialization/JsonContract.cs | 4 +- .../Serialization/JsonDictionaryContract.cs | 2 +- .../Serialization/JsonDynamicContract.cs | 2 +- .../Serialization/JsonFormatterConverter.cs | 2 +- .../JsonISerializableContract.cs | 2 +- .../JsonSerializerInternalBase.cs | 2 +- .../JsonSerializerInternalReader.cs | 18 +- .../JsonSerializerInternalWriter.cs | 12 +- .../Serialization/JsonTypeReflector.cs | 28 +- Src/Newtonsoft.Json/SerializationBinder.cs | 2 +- Src/Newtonsoft.Json/Utilities/ConvertUtils.cs | 16 +- .../Utilities/DateTimeUtils.cs | 4 +- .../Utilities/DictionaryWrapper.cs | 38 +- Src/Newtonsoft.Json/Utilities/DynamicProxy.cs | 2 +- .../Utilities/DynamicProxyMetaObject.cs | 2 +- .../DynamicReflectionDelegateFactory.cs | 2 +- Src/Newtonsoft.Json/Utilities/DynamicUtils.cs | 2 +- .../Utilities/DynamicWrapper.cs | 2 +- .../Utilities/ILGeneratorExtensions.cs | 2 +- .../Utilities/ReflectionUtils.cs | 97 +++--- Src/Newtonsoft.Json/Utilities/StringUtils.cs | 6 +- .../Utilities/TypeExtensions.cs | 105 ++++-- 85 files changed, 1005 insertions(+), 344 deletions(-) create mode 100644 Src/Newtonsoft.Json.Portable.sln create mode 100644 Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable.csproj create mode 100644 Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj diff --git a/Build/build.ps1 b/Build/build.ps1 index c9f8bffb..6ed9db75 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -17,6 +17,7 @@ $workingDir = "$baseDir\Working" $builds = @( @{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true}, + @{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = $null; Framework="net-4.0"; Sign=$true}, @{Name = "Newtonsoft.Json.Metro"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="Metro"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true}, # unsigned SL/WP diff --git a/Src/Newtonsoft.Json.Portable.sln b/Src/Newtonsoft.Json.Portable.sln new file mode 100644 index 00000000..f7ad1865 --- /dev/null +++ b/Src/Newtonsoft.Json.Portable.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}" + ProjectSection(SolutionItems) = preProject + Lib\NUnit\DotNet\nunit.framework.dll = Lib\NUnit\DotNet\nunit.framework.dll + Lib\NUnit\DotNet\nunit.framework.xml = Lib\NUnit\DotNet\nunit.framework.xml + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Portable", "Newtonsoft.Json\Newtonsoft.Json.Portable.csproj", "{959F7F85-C98B-4876-971A-9036224578E4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Tests.Portable", "Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Portable.csproj", "{3E6E2335-B079-4B5B-A65A-9D586914BCBB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {959F7F85-C98B-4876-971A-9036224578E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {959F7F85-C98B-4876-971A-9036224578E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {959F7F85-C98B-4876-971A-9036224578E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {959F7F85-C98B-4876-971A-9036224578E4}.Release|Any CPU.Build.0 = Release|Any CPU + {3E6E2335-B079-4B5B-A65A-9D586914BCBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E6E2335-B079-4B5B-A65A-9D586914BCBB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E6E2335-B079-4B5B-A65A-9D586914BCBB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E6E2335-B079-4B5B-A65A-9D586914BCBB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs index b5073a7c..a99a0cb1 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs @@ -29,7 +29,7 @@ namespace Newtonsoft.Json.Tests.Converters public byte[] NullByteArray { get; set; } } -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) [Test] public void DeserializeBinaryClass() { @@ -87,7 +87,7 @@ namespace Newtonsoft.Json.Tests.Converters byteArrayClass.ByteArray = TestData; byteArrayClass.NullByteArray = null; - string json = JsonConvert.SerializeObject(byteArrayClass, Formatting.Indented, new BinaryConverter()); + string json = JsonConvert.SerializeObject(byteArrayClass, Formatting.Indented); Assert.AreEqual(@"{ ""ByteArray"": ""VGhpcyBpcyBzb21lIHRlc3QgZGF0YSEhIQ=="", @@ -95,7 +95,7 @@ namespace Newtonsoft.Json.Tests.Converters }", json); } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) public class SqlBinaryClass { public SqlBinary SqlBinary { get; set; } @@ -145,7 +145,7 @@ namespace Newtonsoft.Json.Tests.Converters ""NullByteArray"": null }"; - ByteArrayClass byteArrayClass = JsonConvert.DeserializeObject(json, new BinaryConverter()); + ByteArrayClass byteArrayClass = JsonConvert.DeserializeObject(json); CollectionAssert.AreEquivalent(TestData, byteArrayClass.ByteArray); Assert.AreEqual(null, byteArrayClass.NullByteArray); diff --git a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs index 259675b9..340f8a39 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/DataSetConverterTests.cs @@ -1,4 +1,4 @@ -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using Newtonsoft.Json.Converters; #if !NETFX_CORE diff --git a/Src/Newtonsoft.Json.Tests/Converters/DataTableConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/DataTableConverterTests.cs index 7f75c040..92b1e104 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/DataTableConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/DataTableConverterTests.cs @@ -1,4 +1,4 @@ -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; #if !NETFX_CORE using NUnit.Framework; diff --git a/Src/Newtonsoft.Json.Tests/Converters/ExpandoObjectConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/ExpandoObjectConverterTests.cs index 84b43a5f..252bf308 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/ExpandoObjectConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/ExpandoObjectConverterTests.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; diff --git a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs index baea14c8..6ec45ce8 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/XmlNodeConverterTest.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Collections.Generic; using Newtonsoft.Json.Tests.Serialization; diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index ee34d5ba..dbd3f2b9 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -285,7 +285,7 @@ now brown cow?", '"', true); value = null; Assert.AreEqual("null", JsonConvert.ToString(value)); -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) value = DBNull.Value; Assert.AreEqual("null", JsonConvert.ToString(value)); #endif @@ -679,7 +679,7 @@ now brown cow?", '"', true); return (T)converter.ReadJson(reader, typeof(T), null, null); } -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) [Test] public void Async() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/BindingTests.cs b/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/BindingTests.cs index a52b855e..1e22addf 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/BindingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/BindingTests.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using NUnit.Framework; using System.Web.UI; using Newtonsoft.Json.Linq; diff --git a/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/JPropertyDescriptorTests.cs b/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/JPropertyDescriptorTests.cs index 6f3e06fe..41aaf4b4 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/JPropertyDescriptorTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/ComponentModel/JPropertyDescriptorTests.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using NUnit.Framework; using Newtonsoft.Json.Linq; diff --git a/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs index f7ae5a52..5f7d1360 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20) +#if !(NET35 || NET20 || PORTABLE) using System; using System.Collections.Generic; using System.Dynamic; diff --git a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs index 28e65634..5743ab3e 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs @@ -424,7 +424,7 @@ Parameter name: index" } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void ITypedListGetItemProperties() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs index 4e626d4a..7be89521 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs @@ -648,7 +648,7 @@ Parameter name: arrayIndex" Assert.AreEqual(p4, l[1]); } -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) [Test] public void PropertyChanging() { @@ -1205,7 +1205,7 @@ Parameter name: arrayIndex" }); } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void IBindingListSortDirection() { @@ -1391,7 +1391,7 @@ Parameter name: arrayIndex" Assert.AreEqual(2, (int)o["Test1"]); } #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) [Test] public void CollectionChanged() { @@ -1521,7 +1521,7 @@ Parameter name: arrayIndex" Assert.AreEqual("Name2", value); } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void WriteObjectNullDBNullValue() { @@ -1652,7 +1652,7 @@ Parameter name: arrayIndex" }); } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void GetProperties() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs index a1fe7418..7cc11dcc 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JPropertyTests.cs @@ -31,7 +31,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(p, p.Value.Parent); } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void ListChanged() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs index be362553..e163a6f4 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs @@ -708,7 +708,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(a.DeepEquals(a2)); } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void Clone() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index 0764d79e..32ebb260 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -69,7 +69,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual("Pie", v.Value); Assert.AreEqual(JTokenType.String, v.Type); -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) v.Value = DBNull.Value; Assert.AreEqual(DBNull.Value, v.Value); Assert.AreEqual(JTokenType.Null, v.Type); diff --git a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs index 0ef622b9..c0b12d2f 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs @@ -719,7 +719,7 @@ keyword such as type of business."" Assert.AreEqual(new DateTime(2000, 10, 15, 5, 5, 5, DateTimeKind.Utc), d); } -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) [Test] public void CovariantIJEnumerable() { diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable.csproj new file mode 100644 index 00000000..f1e9a73b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Portable.csproj @@ -0,0 +1,326 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3E6E2335-B079-4B5B-A65A-9D586914BCBB} + Library + Properties + Newtonsoft.Json.Tests + Newtonsoft.Json.Tests + + + + + + + + + + + 3.5 + + + v4.0 + 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;PORTABLE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\Release\Portable\ + TRACE;PORTABLE + prompt + 4 + AllRules.ruleset + + + + + 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.Portable + global,NewtonsoftJson + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 10314a99..fdb42886 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -1,4 +1,4 @@ -#if !SILVERLIGHT && !PocketPC && !NET20 && !NET35 && !NETFX_CORE +#if !(SILVERLIGHT || PocketPC || NET20 || NET35 || NETFX_CORE || PORTABLE) using System; using System.Collections.Generic; using System.Globalization; @@ -40,8 +40,8 @@ namespace Newtonsoft.Json.Tests [TestFixture] public class PerformanceTests : TestFixtureBase { - //private const int Iterations = 100; - private const int Iterations = 5000; + private const int Iterations = 100; + //private const int Iterations = 5000; #region Data diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 465543f5..612c9720 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -72,5 +72,5 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.3.14817")] +[assembly: AssemblyFileVersion("4.5.3.14818")] #endif diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index 8d0ac652..57f825cd 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -202,7 +202,7 @@ namespace Newtonsoft.Json.Tests.Schema #if !NET20 && !PocketPC GenerateSchemaAndSerializeFromType(new NullableDateTimeTestClass()); #endif -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) GenerateSchemaAndSerializeFromType(new DataSet()); #endif GenerateSchemaAndSerializeFromType(new object()); @@ -210,7 +210,7 @@ namespace Newtonsoft.Json.Tests.Schema GenerateSchemaAndSerializeFromType("Hi"); GenerateSchemaAndSerializeFromType(new DateTime(2000, 12, 29, 23, 59, 0, DateTimeKind.Utc)); GenerateSchemaAndSerializeFromType(TimeSpan.FromTicks(1000000)); -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) GenerateSchemaAndSerializeFromType(DBNull.Value); #endif GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues()); diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs index 155019ac..2a5ee264 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs @@ -90,7 +90,7 @@ namespace Newtonsoft.Json.Tests.Schema Assert.IsTrue(o.IsValid(schema)); } -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void Generate_DefaultValueAttributeTestClass() { @@ -310,7 +310,7 @@ namespace Newtonsoft.Json.Tests.Schema Assert.IsTrue(v.IsValid(schema)); } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void GenerateSchemaForISerializable() { @@ -325,7 +325,7 @@ namespace Newtonsoft.Json.Tests.Schema } #endif -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) [Test] public void GenerateSchemaForDBNull() { @@ -370,7 +370,7 @@ namespace Newtonsoft.Json.Tests.Schema generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName; generator.ContractResolver = new CustomDirectoryInfoMapper { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif }; @@ -454,7 +454,7 @@ namespace Newtonsoft.Json.Tests.Schema serializer.Converters.Add(new IsoDateTimeConverter()); serializer.ContractResolver = new CustomDirectoryInfoMapper { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableInterface = true #endif }; @@ -474,7 +474,7 @@ namespace Newtonsoft.Json.Tests.Schema generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName; generator.ContractResolver = new CamelCasePropertyNamesContractResolver() { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif }; @@ -519,7 +519,7 @@ namespace Newtonsoft.Json.Tests.Schema }", json); } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void GenerateSchemaSerializable() { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs index 071a03d1..47205adb 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/CamelCasePropertyNamesContractResolverTests.cs @@ -177,7 +177,7 @@ namespace Newtonsoft.Json.Tests.Serialization }", json); } -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) [Test] public void DynamicCamelCasePropertyNames() { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs index 73d92f69..7d94cd76 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/DynamicTests.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections; using System.Collections.Generic; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs index c7ca94af..67bfc89b 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(NET35 || NET20 || SILVERLIGHT || NETFX_CORE) +#if !(NET35 || NET20 || SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Collections.Generic; using System.Data; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 0b7370ac..ffad92d0 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -688,7 +688,7 @@ keyword such as type of business."" string json = JsonConvert.SerializeObject(new ConverableMembers(), Formatting.Indented); string expected = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) expected = @"{ ""String"": ""string"", ""Int32"": 2147483647, @@ -728,7 +728,7 @@ keyword such as type of business."" ConverableMembers c = JsonConvert.DeserializeObject(json); Assert.AreEqual("string", c.String); Assert.AreEqual(double.MaxValue, c.Double); -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) Assert.AreEqual(DBNull.Value, c.DBNull); #endif } @@ -1471,7 +1471,7 @@ keyword such as type of business."" Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]); } -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) [MetadataType(typeof (OptInClassMetadata))] public class OptInClass { @@ -2036,7 +2036,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li { ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif } @@ -2054,11 +2054,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li JsonConvert.DeserializeObject("{ReadTimeout:0}", new JsonSerializerSettings { ContractResolver = new DefaultContractResolver - { -#if !(SILVERLIGHT || NETFX_CORE) + { +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif - } + } }); } @@ -2073,11 +2073,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li JsonConvert.DeserializeObject("{ReadTimeout:''}", new JsonSerializerSettings { ContractResolver = new DefaultContractResolver - { -#if !(SILVERLIGHT || NETFX_CORE) + { +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif - } + } }); } @@ -2092,11 +2092,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li JsonConvert.DeserializeObject("{ReadTimeout:null}", new JsonSerializerSettings { ContractResolver = new DefaultContractResolver - { -#if !(SILVERLIGHT || NETFX_CORE) + { +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif - } + } }); } @@ -2751,7 +2751,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li Assert.AreEqual("value", newModelStateDictionary["key"]); } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) public class ISerializableTestObject : ISerializable { internal string _stringValue; @@ -3243,7 +3243,7 @@ To fix this error either change the environment to be fully trusted, change the } #endif -#if !NET20 && !SILVERLIGHT +#if !(NET20 || SILVERLIGHT || PORTABLE) [Test] public void SerializeDeserializeXNodeProperties() { @@ -3274,7 +3274,7 @@ To fix this error either change the environment to be fully trusted, change the } #endif -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void SerializeDeserializeXmlNodeProperties() { @@ -4150,7 +4150,7 @@ To fix this error either change the environment to be fully trusted, change the }", json); } -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) [Test] public void SerializeExpandoObject() { @@ -5118,7 +5118,7 @@ To fix this error either change the environment to be fully trusted, change the } } -#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE) +#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE) [Test] public void SerializeException1() { @@ -5248,7 +5248,7 @@ To fix this error either change the environment to be fully trusted, change the } } -#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE) +#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) [Test] public void DeserializeConcurrentDictionary() { @@ -5845,7 +5845,7 @@ Parameter name: value" Converters = { new MetroStringConverter() }, Formatting = Formatting.Indented }); - Assert.AreEqual(metroJson, @"{ + Assert.AreEqual(@"{ "":::NAME:::"": "":::APPLE:::"", "":::EXPIRYDATE:::"": ""2012-04-01T00:00:00"", "":::PRICE:::"": 3.99, @@ -5854,7 +5854,7 @@ Parameter name: value" "":::MEDIUM:::"", "":::LARGE:::"" ] -}"); +}", metroJson); //{ // ":::NAME:::": ":::APPLE:::", // ":::EXPIRYDATE:::": "2012-04-01T00:00:00", @@ -5864,11 +5864,6 @@ Parameter name: value" Color[] colors = new []{ Color.Blue, Color.Red, Color.Yellow, Color.Green, Color.Black, Color.Brown }; - string json1 = JsonConvert.SerializeObject(colors); - //[":::GRAY:::", ":::GRAY:::", ":::GRAY:::", ":::GRAY:::", ":::BLACK:::", ":::GRAY:::"] - - Assert.AreEqual(json1, @"[""Blue"",""Red"",""Yellow"",""Green"",""Black"",""Brown""]"); - string json2 = JsonConvert.SerializeObject(colors, new JsonSerializerSettings { ContractResolver = new MetroPropertyNameResolver(), @@ -5876,14 +5871,14 @@ Parameter name: value" Formatting = Formatting.Indented }); - Assert.AreEqual(json2, @"[ + Assert.AreEqual(@"[ "":::GRAY:::"", "":::GRAY:::"", "":::GRAY:::"", "":::GRAY:::"", "":::BLACK:::"", "":::GRAY:::"" -]"); +]", json2); } public class MetroStringConverter : JsonConverter @@ -5933,6 +5928,32 @@ Parameter name: value" } } #endif + + private class FooBar + { + public DateTimeOffset Foo { get; set; } + } + + [Test] + public void TokenFromBson() + { + MemoryStream ms = new MemoryStream(); + BsonWriter writer = new BsonWriter(ms); + writer.WriteStartArray(); + writer.WriteValue("2000-01-02T03:04:05+06:00"); + writer.WriteEndArray(); + + byte[] data = ms.ToArray(); + BsonReader reader = new BsonReader(new MemoryStream(data)) + { + ReadRootValueAsArray = true + }; + + JArray a = (JArray)JArray.ReadFrom(reader); + JValue v = (JValue)a[0]; + Console.WriteLine(v.Value.GetType()); + Console.WriteLine(a.ToString()); + } } public class PersonWithPrivateConstructor diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index 0bfd6974..aac66e94 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -23,6 +23,10 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion +#if PORTABLE +extern alias NewtonsoftJson; +using FormatterAssemblyStyle = NewtonsoftJson::System.Runtime.Serialization.Formatters.FormatterAssemblyStyle; +#endif using System; using System.Collections; using System.Collections.Generic; @@ -135,7 +139,7 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("Name!", ((EmployeeReference)employee).Name); } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void DeserializeTypeNameFromGacAssembly() { @@ -969,7 +973,7 @@ namespace Newtonsoft.Json.Tests.Serialization Binder = new MetroBinder(), ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true #endif } diff --git a/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs index 73fba239..5e63252f 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/WebApiIntegrationTests.cs @@ -34,7 +34,7 @@ namespace Newtonsoft.Json.Tests.Serialization nonSerializedField = "Error" }; -#if !(SILVERLIGHT || NETFX_CORE || NET20) +#if !(SILVERLIGHT || NETFX_CORE || NET20 || PORTABLE) MemoryStream ms = new MemoryStream(); DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(SerializableType)); dataContractJsonSerializer.WriteObject(ms, serializableType); @@ -50,7 +50,7 @@ namespace Newtonsoft.Json.Tests.Serialization { ContractResolver = new DefaultContractResolver { -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = false #endif } @@ -59,7 +59,7 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(expected, json); } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Test] public void SerializeInheritedType() { @@ -89,7 +89,7 @@ namespace Newtonsoft.Json.Tests.Serialization } } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [Serializable] #else [JsonObject(MemberSerialization.Fields)] @@ -119,7 +119,7 @@ namespace Newtonsoft.Json.Tests.Serialization } } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) [NonSerialized] #else [JsonIgnore] diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConverableMembers.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConverableMembers.cs index c9bd722f..b1b002cd 100644 --- a/Src/Newtonsoft.Json.Tests/TestObjects/ConverableMembers.cs +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConverableMembers.cs @@ -41,7 +41,7 @@ namespace Newtonsoft.Json.Tests.TestObjects public ulong ULong = long.MaxValue; public double Double = double.MaxValue; public float Float = float.MaxValue; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) public DBNull DBNull = DBNull.Value; #endif public bool Bool = true; diff --git a/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs index 37b9c7d4..d466fe95 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) using System; using System.Reflection; #if !NETFX_CORE diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs index b95ccbc3..4d7671ee 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ReflectionUtilsTests.cs @@ -1,4 +1,8 @@ -using System; +#if PORTABLE +extern alias NewtonsoftJson; +using FormatterAssemblyStyle = NewtonsoftJson::System.Runtime.Serialization.Formatters.FormatterAssemblyStyle; +#endif +using System; using System.Collections.Generic; using System.Runtime.Serialization.Formatters; #if !NETFX_CORE diff --git a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs index 1abd6122..53fb7b90 100644 --- a/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonBinaryWriter.cs @@ -29,7 +29,7 @@ namespace Newtonsoft.Json.Bson public void Close() { -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) _writer.Close(); #else _writer.Dispose(); diff --git a/Src/Newtonsoft.Json/Bson/BsonReader.cs b/Src/Newtonsoft.Json/Bson/BsonReader.cs index a96d5b88..f14af3fa 100644 --- a/Src/Newtonsoft.Json/Bson/BsonReader.cs +++ b/Src/Newtonsoft.Json/Bson/BsonReader.cs @@ -295,7 +295,7 @@ namespace Newtonsoft.Json.Bson base.Close(); if (CloseInput && _reader != null) -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) _reader.Close(); #else _reader.Dispose(); diff --git a/Src/Newtonsoft.Json/Bson/BsonWriter.cs b/Src/Newtonsoft.Json/Bson/BsonWriter.cs index e595009c..6397589c 100644 --- a/Src/Newtonsoft.Json/Bson/BsonWriter.cs +++ b/Src/Newtonsoft.Json/Bson/BsonWriter.cs @@ -357,7 +357,7 @@ namespace Newtonsoft.Json.Bson { base.WriteValue(value); string s = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) s = value.ToString(CultureInfo.InvariantCulture); #else s = value.ToString(); diff --git a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs index d94ebb5d..65b8695e 100644 --- a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs +++ b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs @@ -23,17 +23,16 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; -#if !SILVERLIGHT && !NETFX_CORE using System.Data.SqlTypes; -#endif using System.Globalization; using Newtonsoft.Json.Utilities; using System.Collections.Generic; namespace Newtonsoft.Json.Converters { -#if !SILVERLIGHT && !PocketPC && !NET20 +#if !NET20 internal interface IBinary { byte[] ToArray(); @@ -45,7 +44,7 @@ namespace Newtonsoft.Json.Converters /// public class BinaryConverter : JsonConverter { -#if !SILVERLIGHT && !PocketPC && !NET20 +#if !NET20 private const string BinaryTypeName = "System.Data.Linq.Binary"; #endif @@ -70,17 +69,16 @@ namespace Newtonsoft.Json.Converters private byte[] GetByteArray(object value) { -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(NET20) if (value.GetType().AssignableToTypeName(BinaryTypeName)) { IBinary binary = DynamicWrapper.CreateWrapper(value); return binary.ToArray(); } #endif -#if !SILVERLIGHT && !NETFX_CORE if (value is SqlBinary) return ((SqlBinary) value).Value; -#endif + throw new Exception("Unexpected value type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, value.GetType())); } @@ -125,14 +123,14 @@ namespace Newtonsoft.Json.Converters } -#if !SILVERLIGHT && !PocketPC && !NET20 +#if !NET20 if (t.AssignableToTypeName(BinaryTypeName)) return Activator.CreateInstance(t, data); #endif -#if !SILVERLIGHT && !NETFX_CORE + if (t == typeof(SqlBinary)) return new SqlBinary(data); -#endif + throw new Exception("Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType)); } @@ -169,15 +167,16 @@ namespace Newtonsoft.Json.Converters /// public override bool CanConvert(Type objectType) { -#if !SILVERLIGHT && !PocketPC && !NET20 +#if !NET20 if (objectType.AssignableToTypeName(BinaryTypeName)) return true; #endif -#if !SILVERLIGHT && !NETFX_CORE + if (objectType == typeof(SqlBinary) || objectType == typeof(SqlBinary?)) return true; -#endif + return false; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs index db7d86ea..833b9c09 100644 --- a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs +++ b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Data; using Newtonsoft.Json.Serialization; diff --git a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs index 05634c11..e4563518 100644 --- a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs +++ b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Data; using Newtonsoft.Json.Serialization; diff --git a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs index e4d6ef65..9e7ecd56 100644 --- a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs +++ b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) using System; using Newtonsoft.Json.Serialization; using System.Globalization; diff --git a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs index 5158beb2..f2f195a8 100644 --- a/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs +++ b/Src/Newtonsoft.Json/Converters/ExpandoObjectConverter.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 2c4beb8d..d3d9e488 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if (!SILVERLIGHT || WINDOWS_PHONE) +#if (!(SILVERLIGHT || PORTABLE) || WINDOWS_PHONE) using System; using System.Collections.Generic; using System.Globalization; diff --git a/Src/Newtonsoft.Json/FormatterAssemblyStyle.cs b/Src/Newtonsoft.Json/FormatterAssemblyStyle.cs index ccfb9a3d..215e866b 100644 --- a/Src/Newtonsoft.Json/FormatterAssemblyStyle.cs +++ b/Src/Newtonsoft.Json/FormatterAssemblyStyle.cs @@ -1,4 +1,4 @@ -#if SILVERLIGHT || PocketPC || NETFX_CORE +#if SILVERLIGHT || PocketPC || NETFX_CORE || PORTABLE namespace System.Runtime.Serialization.Formatters { /// diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index 34333072..3b5edbd1 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -26,14 +26,14 @@ using System; using System.IO; using System.Globalization; -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) using System.Threading.Tasks; #endif using Newtonsoft.Json.Utilities; using System.Xml; using Newtonsoft.Json.Converters; using System.Text; -#if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE) +#if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE) && !PORTABLE using System.Xml.Linq; #endif #if NETFX_CORE @@ -485,7 +485,7 @@ namespace Newtonsoft.Json { string text = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) text = value.ToString("D", CultureInfo.InvariantCulture); #else text = value.ToString("D"); @@ -584,7 +584,7 @@ namespace Newtonsoft.Json return ToString(convertible.ToDateTime(CultureInfo.InvariantCulture)); case TypeCode.Decimal: return ToString(convertible.ToDecimal(CultureInfo.InvariantCulture)); -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) case TypeCode.DBNull: return Null; #endif @@ -631,7 +631,7 @@ namespace Newtonsoft.Json case TypeCode.Double: case TypeCode.DateTime: case TypeCode.Decimal: -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) case TypeCode.DBNull: #endif return true; @@ -752,7 +752,7 @@ namespace Newtonsoft.Json return sw.ToString(); } -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) /// /// Asynchronously serializes the specified object to a JSON string using a collection of . /// @@ -931,7 +931,7 @@ namespace Newtonsoft.Json return deserializedValue; } -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) /// /// Asynchronously deserializes the JSON to the specified .NET type. /// @@ -1026,7 +1026,7 @@ namespace Newtonsoft.Json } } -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) /// /// Asynchronously populates the object with values from the JSON string. /// @@ -1045,7 +1045,7 @@ namespace Newtonsoft.Json } #endif -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || PORTABLE || NETFX_CORE) /// /// Serializes the XML node to a JSON string. /// @@ -1124,7 +1124,7 @@ namespace Newtonsoft.Json } #endif -#if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE) +#if !NET20 && (!(SILVERLIGHT || PORTABLE) || WINDOWS_PHONE) /// /// Serializes the to a JSON string. /// diff --git a/Src/Newtonsoft.Json/JsonReaderException.cs b/Src/Newtonsoft.Json/JsonReaderException.cs index a254600d..946a4351 100644 --- a/Src/Newtonsoft.Json/JsonReaderException.cs +++ b/Src/Newtonsoft.Json/JsonReaderException.cs @@ -31,7 +31,7 @@ namespace Newtonsoft.Json /// /// The exception thrown when an error occurs while reading Json text. /// -#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE) +#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE) [Serializable] #endif public class JsonReaderException : Exception @@ -83,7 +83,7 @@ namespace Newtonsoft.Json { } -#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE) +#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Initializes a new instance of the class. /// diff --git a/Src/Newtonsoft.Json/JsonSerializationException.cs b/Src/Newtonsoft.Json/JsonSerializationException.cs index b26463e4..b0978408 100644 --- a/Src/Newtonsoft.Json/JsonSerializationException.cs +++ b/Src/Newtonsoft.Json/JsonSerializationException.cs @@ -33,7 +33,7 @@ namespace Newtonsoft.Json /// /// The exception thrown when an error occurs during Json serialization or deserialization. /// -#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE) +#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE) [Serializable] #endif public class JsonSerializationException : Exception @@ -66,7 +66,7 @@ namespace Newtonsoft.Json { } -#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE) +#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Initializes a new instance of the class. /// diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index 001a0372..3d033a1a 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -1579,7 +1579,7 @@ namespace Newtonsoft.Json base.Close(); if (CloseInput && _reader != null) -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) _reader.Close(); #else _reader.Dispose(); diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs index 11437865..2a5c8ce2 100644 --- a/Src/Newtonsoft.Json/JsonTextWriter.cs +++ b/Src/Newtonsoft.Json/JsonTextWriter.cs @@ -136,7 +136,7 @@ namespace Newtonsoft.Json base.Close(); if (CloseOutput && _writer != null) -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) _writer.Close(); #else _writer.Dispose(); diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs index 30e87f47..66676af6 100644 --- a/Src/Newtonsoft.Json/JsonWriter.cs +++ b/Src/Newtonsoft.Json/JsonWriter.cs @@ -1212,7 +1212,7 @@ namespace Newtonsoft.Json case TypeCode.Decimal: WriteValue(convertible.ToDecimal(CultureInfo.InvariantCulture)); return; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) case TypeCode.DBNull: WriteNull(); return; diff --git a/Src/Newtonsoft.Json/JsonWriterException.cs b/Src/Newtonsoft.Json/JsonWriterException.cs index f88f793d..9dc8c440 100644 --- a/Src/Newtonsoft.Json/JsonWriterException.cs +++ b/Src/Newtonsoft.Json/JsonWriterException.cs @@ -33,7 +33,7 @@ namespace Newtonsoft.Json /// /// The exception thrown when an error occurs while reading Json text. /// -#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE) +#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE) [Serializable] #endif public class JsonWriterException : Exception @@ -66,7 +66,7 @@ namespace Newtonsoft.Json { } -#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE) +#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Initializes a new instance of the class. /// diff --git a/Src/Newtonsoft.Json/Linq/IJEnumerable.cs b/Src/Newtonsoft.Json/Linq/IJEnumerable.cs index abe73f52..b07c475e 100644 --- a/Src/Newtonsoft.Json/Linq/IJEnumerable.cs +++ b/Src/Newtonsoft.Json/Linq/IJEnumerable.cs @@ -7,7 +7,7 @@ namespace Newtonsoft.Json.Linq /// /// The type of token public interface IJEnumerable< -#if !(NET20 || NET35 || SILVERLIGHT) +#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE) out #endif T> : IEnumerable where T : JToken diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index 04ef9682..eae6718c 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -25,7 +25,9 @@ using System; using System.Collections.Generic; +#if !PORTABLE using System.Collections.Specialized; +#endif using System.Threading; using Newtonsoft.Json.Utilities; using System.Collections; @@ -43,16 +45,17 @@ namespace Newtonsoft.Json.Linq /// Represents a token that can contain other tokens. /// public abstract class JContainer : JToken, IList -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) , ITypedList, IBindingList -#else - , IList, INotifyCollectionChanged +#elif !PORTABLE + , INotifyCollectionChanged #endif -#if !(SILVERLIGHT || NET20 || NET35 || NETFX_CORE) + , IList +#if !(SILVERLIGHT || NET20 || NET35 || NETFX_CORE || PORTABLE) , INotifyCollectionChanged #endif { -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Occurs when the list changes or an item in the list changes. /// @@ -63,7 +66,7 @@ namespace Newtonsoft.Json.Linq /// public event AddingNewEventHandler AddingNew; #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) /// /// Occurs when the items list of the collection has changed, or the collection is reset. /// @@ -99,7 +102,7 @@ namespace Newtonsoft.Json.Linq throw new InvalidOperationException("Cannot change {0} during a collection change event.".FormatWith(CultureInfo.InvariantCulture, GetType())); } - #if !SILVERLIGHT && !NETFX_CORE + #if !(SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Raises the event. /// @@ -133,7 +136,7 @@ namespace Newtonsoft.Json.Linq } } #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) /// /// Raises the event. /// @@ -326,11 +329,11 @@ namespace Newtonsoft.Json.Linq ChildrenTokens.Insert(index, item); -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) if (ListChanged != null) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index)); #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) if (CollectionChanged != null) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); #endif @@ -360,10 +363,10 @@ namespace Newtonsoft.Json.Linq ChildrenTokens.RemoveAt(index); -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index)); #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); #endif } @@ -422,10 +425,10 @@ namespace Newtonsoft.Json.Linq existing.Previous = null; existing.Next = null; -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index)); #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, item, existing, index)); #endif } @@ -443,10 +446,10 @@ namespace Newtonsoft.Json.Linq ChildrenTokens.Clear(); -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); #endif } @@ -715,7 +718,7 @@ namespace Newtonsoft.Json.Linq return hashCode; } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) string ITypedList.GetListName(PropertyDescriptor[] listAccessors) { return string.Empty; @@ -894,7 +897,7 @@ namespace Newtonsoft.Json.Linq #region IBindingList Members -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) void IBindingList.AddIndex(PropertyDescriptor property) { } diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 905ee750..4bc1c10a 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -26,9 +26,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +#if !PORTABLE using System.Collections.Specialized; +#endif using System.ComponentModel; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; using System.Linq.Expressions; #endif @@ -47,10 +49,10 @@ namespace Newtonsoft.Json.Linq /// Represents a JSON object. /// public class JObject : JContainer, IDictionary, INotifyPropertyChanged -#if !(PocketPC || SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) , ICustomTypeDescriptor #endif -#if !(PocketPC || SILVERLIGHT || NET20 || NETFX_CORE) +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) , INotifyPropertyChanging #endif { @@ -70,7 +72,7 @@ namespace Newtonsoft.Json.Linq /// public event PropertyChangedEventHandler PropertyChanged; -#if !(PocketPC || SILVERLIGHT || NET20 || NETFX_CORE) +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) /// /// Occurs when a property value is changing. /// @@ -153,17 +155,17 @@ namespace Newtonsoft.Json.Linq internal void InternalPropertyChanged(JProperty childProperty) { OnPropertyChanged(childProperty.Name); -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty))); #endif -#if SILVERLIGHT || !(NET20 || NET35) +#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE) OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, childProperty, childProperty, IndexOfItem(childProperty))); #endif } internal void InternalPropertyChanging(JProperty childProperty) { -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) OnPropertyChanging(childProperty.Name); #endif } @@ -266,7 +268,7 @@ namespace Newtonsoft.Json.Linq } else { -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) OnPropertyChanging(propertyName); #endif Add(new JProperty(propertyName, value)); @@ -517,7 +519,7 @@ namespace Newtonsoft.Json.Linq PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || NET20) /// /// Raises the event with the provided arguments. /// @@ -529,7 +531,7 @@ namespace Newtonsoft.Json.Linq } #endif -#if !PocketPC && !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) // include custom type descriptor on JObject rather than use a provider because the properties are specific to a type #region ICustomTypeDescriptor /// @@ -688,7 +690,7 @@ namespace Newtonsoft.Json.Linq #endregion #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) /// /// Returns the responsible for binding operations performed on this object. /// diff --git a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs index 2c290e3c..6f2282ba 100644 --- a/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs +++ b/Src/Newtonsoft.Json/Linq/JPropertyDescriptor.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.ComponentModel; using Newtonsoft.Json.Utilities; diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index dcd5b29b..e39780b4 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; using System.Linq.Expressions; #endif @@ -46,10 +46,10 @@ namespace Newtonsoft.Json.Linq /// Represents an abstract JSON token. /// public abstract class JToken : IJEnumerable, IJsonLineInfo -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) , ICloneable #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) , IDynamicMetaObjectProvider #endif { @@ -1318,7 +1318,7 @@ namespace Newtonsoft.Json.Linq return p.Evaluate(this, errorWhenNoMatch); } -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) /// /// Returns the responsible for binding operations performed on this object. /// @@ -1344,7 +1344,7 @@ namespace Newtonsoft.Json.Linq } #endif -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) object ICloneable.Clone() { return DeepClone(); diff --git a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs index a9d52b8f..cafaf278 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs @@ -302,7 +302,7 @@ namespace Newtonsoft.Json.Linq { base.WriteValue(value); string s = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) s = value.ToString(CultureInfo.InvariantCulture); #else s = value.ToString(); diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 18fe5490..9ed6d14a 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -27,7 +27,7 @@ using System; using System.Collections.Generic; using Newtonsoft.Json.Utilities; using System.Globalization; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; using System.Linq.Expressions; #endif @@ -277,7 +277,7 @@ namespace Newtonsoft.Json.Linq return d1.CompareTo(d2); } -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) private static bool Operation(ExpressionType operation, object objA, object objB, out object result) { if (objA is string || objB is string) @@ -418,7 +418,7 @@ namespace Newtonsoft.Json.Linq { if (value == null) return JTokenType.Null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) else if (value == DBNull.Value) return JTokenType.Null; #endif @@ -681,7 +681,7 @@ namespace Newtonsoft.Json.Linq return _value.ToString(); } -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) /// /// Returns the responsible for binding operations performed on this object. /// diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj new file mode 100644 index 00000000..13e03354 --- /dev/null +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Portable.csproj @@ -0,0 +1,212 @@ + + + + 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} + + + true + full + false + bin\Debug\Portable\ + TRACE;DEBUG;PORTABLE + prompt + 4 + + + pdbonly + true + bin\Release\Portable\ + TRACE;PORTABLE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 37ae3b9a..98899305 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -38,6 +38,8 @@ using System.Security; [assembly: AssemblyTitle("Json.NET Silverlight")] #elif PocketPC [assembly: AssemblyTitle("Json.NET Compact")] +#elif PORTABLE +[assembly: AssemblyTitle("Json.NET Portable")] #elif NETFX_CORE [assembly: AssemblyTitle("Json.NET Metro")] [assembly: AllowPartiallyTrustedCallers] @@ -68,7 +70,7 @@ using System.Security; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] - +#if !PORTABLE // Setting ComVisible to false makes the types in this assembly not visible // to COM componenets. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. @@ -76,6 +78,7 @@ using System.Security; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("9ca358aa-317b-4925-8ada-4a29e943a363")] +#endif // Version information for an assembly consists of the following four values: // @@ -88,7 +91,7 @@ using System.Security; // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] #if !PocketPC -[assembly: AssemblyFileVersion("4.5.3.14817")] +[assembly: AssemblyFileVersion("4.5.3.14818")] #endif [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs index b5201c79..afafffa4 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaException.cs @@ -31,7 +31,7 @@ namespace Newtonsoft.Json.Schema /// /// Returns detailed information about the schema exception. /// -#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE) +#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE) [Serializable] #endif public class JsonSchemaException : Exception @@ -83,7 +83,7 @@ namespace Newtonsoft.Json.Schema { } - #if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE) + #if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Initializes a new instance of the class. /// diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs index 5513131d..cf4f6d79 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs @@ -182,7 +182,7 @@ namespace Newtonsoft.Json.Schema if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Description)) return containerAttribute.Description; -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) DescriptionAttribute descriptionAttribute = ReflectionUtils.GetAttribute(type); if (descriptionAttribute != null) return descriptionAttribute.Description; @@ -330,14 +330,14 @@ namespace Newtonsoft.Json.Schema } } break; -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) 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 || PORTABLE) case JsonContractType.Dynamic: #endif case JsonContractType.Linq: @@ -389,7 +389,7 @@ namespace Newtonsoft.Json.Schema CurrentSchema.AllowAdditionalProperties = false; } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) private void GenerateISerializableContract(Type type, JsonISerializableContract contract) { CurrentSchema.AllowAdditionalProperties = true; @@ -430,7 +430,7 @@ namespace Newtonsoft.Json.Schema case TypeCode.Empty: case TypeCode.Object: return schemaType | JsonSchemaType.String; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) case TypeCode.DBNull: return schemaType | JsonSchemaType.Null; #endif diff --git a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs index e1526ad0..97ba9043 100644 --- a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs +++ b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs @@ -26,7 +26,7 @@ using System; using System.Reflection; using Newtonsoft.Json.Utilities; -#if NETFX_CORE +#if NETFX_CORE || PORTABLE using ICustomAttributeProvider = Newtonsoft.Json.Utilities.CustomAttributeProvider; #endif diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 7fee6a71..fb23cdea 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -25,18 +25,18 @@ using System; using System.Collections; -#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE) +#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) using System.Collections.Concurrent; #endif using System.Collections.Generic; using System.ComponentModel; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; #endif using System.Globalization; using System.Reflection; using System.Runtime.Serialization; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) using System.Security.Permissions; #endif using System.Xml.Serialization; @@ -44,7 +44,7 @@ using Newtonsoft.Json.Converters; using Newtonsoft.Json.Utilities; using Newtonsoft.Json.Linq; using System.Runtime.CompilerServices; -#if NETFX_CORE +#if NETFX_CORE || PORTABLE using ICustomAttributeProvider = Newtonsoft.Json.Utilities.CustomAttributeProvider; #endif #if NET20 @@ -97,21 +97,21 @@ namespace Newtonsoft.Json.Serialization } private static readonly IList BuiltInConverters = new List { -#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) new EntityKeyMemberConverter(), #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) new ExpandoObjectConverter(), #endif - new BinaryConverter(), - new KeyValuePairConverter(), -#if (!SILVERLIGHT || WINDOWS_PHONE) +#if (!(SILVERLIGHT || PORTABLE) || WINDOWS_PHONE) new XmlNodeConverter(), #endif -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) + new BinaryConverter(), new DataSetConverter(), new DataTableConverter(), #endif + new KeyValuePairConverter(), new BsonObjectIdConverter() }; @@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Serialization /// public bool SerializeCompilerGeneratedMembers { get; set; } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// 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) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) IgnoreSerializableAttribute = true; #endif @@ -256,7 +256,7 @@ namespace Newtonsoft.Json.Serialization protected virtual List GetSerializableMembers(Type objectType) { bool ignoreSerializableAttribute; -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) ignoreSerializableAttribute = IgnoreSerializableAttribute; #else ignoreSerializableAttribute = true; @@ -349,7 +349,7 @@ namespace Newtonsoft.Json.Serialization InitializeContract(contract); bool ignoreSerializableAttribute; -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) ignoreSerializableAttribute = IgnoreSerializableAttribute; #else ignoreSerializableAttribute = true; @@ -553,7 +553,7 @@ namespace Newtonsoft.Json.Serialization if (onDeserialized != null) { // ConcurrentDictionary throws an error here so don't use its OnDeserialized - http://json.codeplex.com/discussions/257093 -#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE) +#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) if (!t.IsGenericType() || (t.GetGenericTypeDefinition() != typeof(ConcurrentDictionary<,>))) contract.OnDeserialized = onDeserialized; #else @@ -660,7 +660,7 @@ namespace Newtonsoft.Json.Serialization return contract; } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) /// /// Creates a for the given type. /// @@ -683,7 +683,7 @@ namespace Newtonsoft.Json.Serialization } #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) /// /// Creates a for the given type. /// @@ -744,12 +744,12 @@ namespace Newtonsoft.Json.Serialization if (CanConvertToString(t)) return CreateStringContract(objectType); -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) if (!IgnoreSerializableInterface && typeof(ISerializable).IsAssignableFrom(t)) return CreateISerializableContract(objectType); #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(t)) return CreateDynamicContract(objectType); #endif @@ -759,7 +759,7 @@ namespace Newtonsoft.Json.Serialization internal static bool CanConvertToString(Type type) { -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) TypeConverter converter = ConvertUtils.GetConverter(type); // use the objectType's TypeConverter if it has one and can convert to a string @@ -863,7 +863,7 @@ namespace Newtonsoft.Json.Serialization // warning - this method use to cause errors with Intellitrace. Retest in VS Ultimate after changes IValueProvider valueProvider; -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) if (DynamicCodeGeneration) valueProvider = new DynamicValueProvider(member); else @@ -909,7 +909,7 @@ namespace Newtonsoft.Json.Serialization DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); MemberInfo memberInfo = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) memberInfo = attributeProvider as MemberInfo; #else memberInfo = attributeProvider.UnderlyingObject as MemberInfo; @@ -957,7 +957,7 @@ namespace Newtonsoft.Json.Serialization } bool hasJsonIgnoreAttribute = JsonTypeReflector.GetAttribute(attributeProvider) != null -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) || JsonTypeReflector.GetAttribute(attributeProvider) != null #endif ; diff --git a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs index a5b577e6..ed1c9043 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultSerializationBinder.cs @@ -49,7 +49,7 @@ namespace Newtonsoft.Json.Serialization { Assembly assembly; -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) // look, I don't like using obsolete methods as much as you do but this is the only way // Assembly.Load won't check the GAC for a partial name #pragma warning disable 618,612 diff --git a/Src/Newtonsoft.Json/Serialization/DynamicValueProvider.cs b/Src/Newtonsoft.Json/Serialization/DynamicValueProvider.cs index 847a2efc..7bedb5c6 100644 --- a/Src/Newtonsoft.Json/Serialization/DynamicValueProvider.cs +++ b/Src/Newtonsoft.Json/Serialization/DynamicValueProvider.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) using System; using System.Collections.Generic; #if NET20 diff --git a/Src/Newtonsoft.Json/Serialization/JsonContract.cs b/Src/Newtonsoft.Json/Serialization/JsonContract.cs index 8826584e..568da9ce 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonContract.cs @@ -41,10 +41,10 @@ namespace Newtonsoft.Json.Serialization Primitive, String, Dictionary, -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) Dynamic, #endif -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) Serializable, #endif Linq diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index 555539b1..4bae99db 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -105,7 +105,7 @@ namespace Newtonsoft.Json.Serialization internal IWrappedDictionary CreateWrapper(object dictionary) { -#if !NETFX_CORE +#if !(NETFX_CORE) if (dictionary is IDictionary && (DictionaryValueType == null || !_isDictionaryValueTypeNullableType)) return new DictionaryWrapper((IDictionary)dictionary); #endif diff --git a/Src/Newtonsoft.Json/Serialization/JsonDynamicContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDynamicContract.cs index 0919b157..1a3ff5c5 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDynamicContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDynamicContract.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; using System.Reflection; diff --git a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs index 1e1ac779..4ecbdb21 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonFormatterConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Globalization; using System.Runtime.Serialization; diff --git a/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs b/Src/Newtonsoft.Json/Serialization/JsonISerializableContract.cs index c3b91938..560ef74d 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 && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; namespace Newtonsoft.Json.Serialization diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs index fc54da6e..dd686d98 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalBase.cs @@ -42,7 +42,7 @@ namespace Newtonsoft.Json.Serialization int IEqualityComparer.GetHashCode(object obj) { -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) // put objects in a bucket based on their reference return RuntimeHelpers.GetHashCode(obj); #else diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index aa6ec8a9..543fc243 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -27,7 +27,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; #endif using System.Globalization; @@ -46,7 +46,7 @@ namespace Newtonsoft.Json.Serialization internal class JsonSerializerInternalReader : JsonSerializerInternalBase { private JsonSerializerProxy _internalSerializer; -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) private JsonFormatterConverter _formatterConverter; #endif @@ -134,7 +134,7 @@ namespace Newtonsoft.Json.Serialization return _internalSerializer; } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) private JsonFormatterConverter GetFormatterConverter() { if (_formatterConverter == null) @@ -268,7 +268,7 @@ namespace Newtonsoft.Json.Serialization return constructorName; case JsonToken.Null: case JsonToken.Undefined: -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) if (objectType == typeof (DBNull)) return DBNull.Value; #endif @@ -462,12 +462,12 @@ namespace Newtonsoft.Json.Serialization return CreateAndPopulateDictionary(reader, dictionaryContract, id); return PopulateDictionary(dictionaryContract.CreateWrapper(existingValue), reader, dictionaryContract, id); -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) case JsonContractType.Dynamic: JsonDynamicContract dynamicContract = (JsonDynamicContract) contract; return CreateDynamic(reader, dynamicContract, id); #endif -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) case JsonContractType.Serializable: JsonISerializableContract serializableContract = (JsonISerializableContract) contract; return CreateISerializable(reader, serializableContract, id); @@ -521,7 +521,7 @@ To force JSON arrays to deserialize add the JsonArrayAttribute to the type.".For private bool HasDefinedType(Type type) { return (type != null && type != typeof (object) && !typeof (JToken).IsSubclassOf(type) -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) && type != typeof (IDynamicMetaObjectProvider) #endif ); @@ -824,7 +824,7 @@ To force JSON arrays to deserialize add the JsonArrayAttribute to the type.".For throw CreateSerializationException(reader, "Unexpected end when deserializing array."); } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, string id) { Type objectType = contract.UnderlyingType; @@ -875,7 +875,7 @@ To fix this error either change the environment to be fully trusted, change the } #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) private object CreateDynamic(JsonReader reader, JsonDynamicContract contract, string id) { IDynamicMetaObjectProvider newObject = null; diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index f54a0f7b..e3aa535c 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -27,7 +27,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System.Dynamic; #endif using System.Globalization; @@ -135,12 +135,12 @@ namespace Newtonsoft.Json.Serialization JsonDictionaryContract dictionaryContract = (JsonDictionaryContract) valueContract; SerializeDictionary(writer, dictionaryContract.CreateWrapper(value), dictionaryContract, member, collectionValueContract); break; -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) case JsonContractType.Dynamic: SerializeDynamic(writer, (IDynamicMetaObjectProvider) value, (JsonDynamicContract) valueContract, member, collectionValueContract); break; #endif -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) case JsonContractType.Serializable: SerializeISerializable(writer, (ISerializable) value, (JsonISerializableContract) valueContract, member, collectionValueContract); break; @@ -248,7 +248,7 @@ namespace Newtonsoft.Json.Serialization internal static bool TryConvertToString(object value, Type type, out string s) { -#if !(PocketPC || NETFX_CORE) +#if !(PocketPC || NETFX_CORE || PORTABLE) TypeConverter converter = ConvertUtils.GetConverter(type); // use the objectType's TypeConverter if it has one and can convert to a string @@ -484,7 +484,7 @@ namespace Newtonsoft.Json.Serialization return writeMetadataObject; } -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) #if !NET20 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Security.SecuritySafeCriticalAttribute")] [SecuritySafeCritical] @@ -518,7 +518,7 @@ To fix this error either change the environment to be fully trusted, change the } #endif -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContract collectionValueContract) { contract.InvokeOnSerializing(value, Serializer.Context); diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index 00b85bec..c9861984 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -27,11 +27,11 @@ using System; using System.ComponentModel; using System.Globalization; using System.Reflection; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) using System.Security.Permissions; #endif using Newtonsoft.Json.Utilities; -#if NETFX_CORE +#if NETFX_CORE || PORTABLE using ICustomAttributeProvider = Newtonsoft.Json.Utilities.CustomAttributeProvider; #endif #if NET20 @@ -62,7 +62,7 @@ namespace Newtonsoft.Json.Serialization public const string SpecifiedPostfix = "Specified"; private static readonly ThreadSafeStore JsonConverterTypeCache = new ThreadSafeStore(GetJsonConverterTypeFromAttribute); -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) private static readonly ThreadSafeStore AssociatedMetadataTypesCache = new ThreadSafeStore(GetAssociateMetadataTypeFromAttribute); private const string MetadataTypeAttributeTypeName = @@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Serialization return GetJsonContainerAttribute(type) as JsonArrayAttribute; } -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) public static SerializableAttribute GetSerializableAttribute(Type type) { return CachedAttributeGetter.GetAttribute(type.GetCustomAttributeProvider()); @@ -171,7 +171,7 @@ namespace Newtonsoft.Json.Serialization return MemberSerialization.OptIn; #endif -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) if (!ignoreSerializableAttribute) { SerializableAttribute serializableAttribute = GetSerializableAttribute(objectType); @@ -200,7 +200,7 @@ namespace Newtonsoft.Json.Serialization public static JsonConverter GetJsonConverter(ICustomAttributeProvider attributeProvider, Type targetConvertedType) { object provider = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) provider = attributeProvider as MemberInfo; #else provider = attributeProvider.UnderlyingObject; @@ -221,7 +221,7 @@ namespace Newtonsoft.Json.Serialization return null; } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) #if !PocketPC public static TypeConverter GetTypeConverter(Type type) { @@ -239,7 +239,7 @@ namespace Newtonsoft.Json.Serialization } #endif -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) private static Type GetAssociatedMetadataType(Type type) { return AssociatedMetadataTypesCache.Get(type); @@ -284,7 +284,7 @@ namespace Newtonsoft.Json.Serialization { T attribute; -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) Type metadataType = GetAssociatedMetadataType(type); if (metadataType != null) { @@ -312,7 +312,7 @@ namespace Newtonsoft.Json.Serialization { T attribute; -#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE +#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE) Type metadataType = GetAssociatedMetadataType(memberInfo.DeclaringType); if (metadataType != null) { @@ -352,7 +352,7 @@ namespace Newtonsoft.Json.Serialization public static T GetAttribute(ICustomAttributeProvider attributeProvider) where T : Attribute { object provider = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) provider = attributeProvider; #else provider = attributeProvider.UnderlyingObject; @@ -390,7 +390,7 @@ namespace Newtonsoft.Json.Serialization { if (_dynamicCodeGeneration == null) { -#if !PocketPC && !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) try { new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand(); @@ -419,7 +419,7 @@ namespace Newtonsoft.Json.Serialization { if (_fullyTrusted == null) { -#if (NETFX_CORE || SILVERLIGHT) +#if (NETFX_CORE || SILVERLIGHT || PORTABLE) _fullyTrusted = false; #elif !(NET20 || NET35) AppDomain appDomain = AppDomain.CurrentDomain; @@ -446,7 +446,7 @@ namespace Newtonsoft.Json.Serialization { get { -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) if (DynamicCodeGeneration) return DynamicReflectionDelegateFactory.Instance; #endif diff --git a/Src/Newtonsoft.Json/SerializationBinder.cs b/Src/Newtonsoft.Json/SerializationBinder.cs index 74695427..69307475 100644 --- a/Src/Newtonsoft.Json/SerializationBinder.cs +++ b/Src/Newtonsoft.Json/SerializationBinder.cs @@ -1,4 +1,4 @@ -#if SILVERLIGHT || PocketPC || NETFX_CORE +#if SILVERLIGHT || PocketPC || NETFX_CORE || PORTABLE using System; using System.Reflection; diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index 8f80e957..33dc25ad 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -32,7 +32,7 @@ using System.Reflection; using Newtonsoft.Json.Utilities.LinqBridge; #endif -#if !(SILVERLIGHT || NETFX_CORE) +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System.Data.SqlTypes; #endif #if NETFX_CORE @@ -134,7 +134,7 @@ namespace Newtonsoft.Json.Utilities public static TypeCode GetTypeCode(object o) { -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) return System.Convert.GetTypeCode(o); #else return GetTypeCode(o.GetType()); @@ -330,14 +330,14 @@ namespace Newtonsoft.Json.Utilities if (targetType == typeof (Uri)) return new Uri((string) initialValue); if (targetType == typeof (TimeSpan)) -#if !(NET35 || NET20 || SILVERLIGHT) +#if !(NET35 || NET20 || SILVERLIGHT || PORTABLE) return TimeSpan.Parse((string) initialValue, CultureInfo.InvariantCulture); #else return TimeSpan.Parse((string)initialValue); #endif } -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) // see if source or target types have a TypeConverter that converts between the two TypeConverter toConverter = GetConverter(initialType); @@ -361,7 +361,7 @@ namespace Newtonsoft.Json.Utilities #endif } #endif -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) // handle DBNull and INullable if (initialValue == DBNull.Value) { @@ -371,7 +371,7 @@ namespace Newtonsoft.Json.Utilities throw new Exception("Can not convert null {0} into non-nullable {1}.".FormatWith(CultureInfo.InvariantCulture, initialType, targetType)); } #endif -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) if (initialValue is INullable) return EnsureTypeAssignable(ToValue((INullable)initialValue), initialType, targetType); #endif @@ -448,7 +448,7 @@ namespace Newtonsoft.Json.Utilities throw new Exception("Could not cast or convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, (initialType != null) ? initialType.ToString() : "{null}", targetType)); } -#if !SILVERLIGHT && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) public static object ToValue(INullable nullableValue) { if (nullableValue == null) @@ -468,7 +468,7 @@ namespace Newtonsoft.Json.Utilities } #endif -#if !PocketPC && !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) internal static TypeConverter GetConverter(Type t) { return JsonTypeReflector.GetTypeConverter(t); diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs index b3100801..229b15de 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs @@ -15,14 +15,14 @@ namespace Newtonsoft.Json.Utilities public static TimeSpan GetUtcOffset(this DateTime d) { -#if PocketPC || NET20 +#if NET20 return TimeZone.CurrentTimeZone.GetUtcOffset(d); #else return TimeZoneInfo.Local.GetUtcOffset(d); #endif } -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) public static XmlDateTimeSerializationMode ToSerializationMode(DateTimeKind kind) { switch (kind) diff --git a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs index c1c7dc6c..1199244b 100644 --- a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs @@ -10,7 +10,7 @@ using System.Linq; namespace Newtonsoft.Json.Utilities { -#if NETFX_CORE +#if (NETFX_CORE) internal interface IDictionary : ICollection { object this[object key] { get; set; } @@ -85,7 +85,7 @@ namespace Newtonsoft.Json.Utilities _dictionary.Add(key, value); else #endif - _genericDictionary.Add(key, value); + _genericDictionary.Add(key, value); } public bool ContainsKey(TKey key) @@ -95,7 +95,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.Contains(key); else #endif - return _genericDictionary.ContainsKey(key); + return _genericDictionary.ContainsKey(key); } public ICollection Keys @@ -107,7 +107,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.Keys.Cast().ToList(); else #endif - return _genericDictionary.Keys; + return _genericDictionary.Keys; } } @@ -182,7 +182,7 @@ namespace Newtonsoft.Json.Utilities _dictionary[key] = value; else #endif - _genericDictionary[key] = value; + _genericDictionary[key] = value; } } @@ -193,7 +193,7 @@ namespace Newtonsoft.Json.Utilities ((IList)_dictionary).Add(item); else #endif - _genericDictionary.Add(item); + _genericDictionary.Add(item); } public void Clear() @@ -203,7 +203,7 @@ namespace Newtonsoft.Json.Utilities _dictionary.Clear(); else #endif - _genericDictionary.Clear(); + _genericDictionary.Clear(); } public bool Contains(KeyValuePair item) @@ -213,7 +213,7 @@ namespace Newtonsoft.Json.Utilities return ((IList)_dictionary).Contains(item); else #endif - return _genericDictionary.Contains(item); + return _genericDictionary.Contains(item); } public void CopyTo(KeyValuePair[] array, int arrayIndex) @@ -242,7 +242,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.Count; else #endif - return _genericDictionary.Count; + return _genericDictionary.Count; } } @@ -255,7 +255,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.IsReadOnly; else #endif - return _genericDictionary.IsReadOnly; + return _genericDictionary.IsReadOnly; } } @@ -297,7 +297,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.Cast().Select(de => new KeyValuePair((TKey)de.Key, (TValue)de.Value)).GetEnumerator(); else #endif - return _genericDictionary.GetEnumerator(); + return _genericDictionary.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() @@ -312,7 +312,7 @@ namespace Newtonsoft.Json.Utilities _dictionary.Add(key, value); else #endif - _genericDictionary.Add((TKey)key, (TValue)value); + _genericDictionary.Add((TKey)key, (TValue)value); } object IDictionary.this[object key] @@ -324,7 +324,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary[key]; else #endif - return _genericDictionary[(TKey)key]; + return _genericDictionary[(TKey)key]; } set { @@ -333,7 +333,7 @@ namespace Newtonsoft.Json.Utilities _dictionary[key] = value; else #endif - _genericDictionary[(TKey)key] = (TValue)value; + _genericDictionary[(TKey)key] = (TValue)value; } } @@ -385,7 +385,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.GetEnumerator(); else #endif - return new DictionaryEnumerator(_genericDictionary.GetEnumerator()); + return new DictionaryEnumerator(_genericDictionary.GetEnumerator()); } #if !NETFX_CORE @@ -427,7 +427,7 @@ namespace Newtonsoft.Json.Utilities _dictionary.Remove(key); else #endif - _genericDictionary.Remove((TKey)key); + _genericDictionary.Remove((TKey)key); } #if !NETFX_CORE @@ -450,7 +450,7 @@ namespace Newtonsoft.Json.Utilities _dictionary.CopyTo(array, index); else #endif - _genericDictionary.CopyTo((KeyValuePair[])array, index); + _genericDictionary.CopyTo((KeyValuePair[])array, index); } bool ICollection.IsSynchronized @@ -462,7 +462,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary.IsSynchronized; else #endif - return false; + return false; } } @@ -486,7 +486,7 @@ namespace Newtonsoft.Json.Utilities return _dictionary; else #endif - return _genericDictionary; + return _genericDictionary; } } } diff --git a/Src/Newtonsoft.Json/Utilities/DynamicProxy.cs b/Src/Newtonsoft.Json/Utilities/DynamicProxy.cs index fc4e4962..641fb8fc 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicProxy.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicProxy.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; using System.Dynamic; diff --git a/Src/Newtonsoft.Json/Utilities/DynamicProxyMetaObject.cs b/Src/Newtonsoft.Json/Utilities/DynamicProxyMetaObject.cs index 8530c05d..85e61a58 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicProxyMetaObject.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicProxyMetaObject.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; using System.Dynamic; diff --git a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs index 168a7328..bb341b52 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicReflectionDelegateFactory.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) using System; using System.Collections.Generic; #if NET20 diff --git a/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs b/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs index b028d618..7b04e451 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicUtils.cs @@ -1,4 +1,4 @@ -#if !(NET35 || NET20 || WINDOWS_PHONE) +#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) using System; using System.Collections.Generic; using System.Dynamic; diff --git a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs index 9d8d6806..4a5d36ee 100644 --- a/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DynamicWrapper.cs @@ -1,4 +1,4 @@ -#if !SILVERLIGHT && !PocketPC && !NETFX_CORE +#if !(SILVERLIGHT || NETFX_CORE || PORTABLE) using System; using System.Collections.Generic; using System.IO; diff --git a/Src/Newtonsoft.Json/Utilities/ILGeneratorExtensions.cs b/Src/Newtonsoft.Json/Utilities/ILGeneratorExtensions.cs index b3cdf51f..be7d4fa2 100644 --- a/Src/Newtonsoft.Json/Utilities/ILGeneratorExtensions.cs +++ b/Src/Newtonsoft.Json/Utilities/ILGeneratorExtensions.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) using System; using System.Reflection.Emit; using System.Reflection; diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index 1c6984e7..843667fa 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -31,7 +31,7 @@ using System.Globalization; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Text; -#if NETFX_CORE +#if NETFX_CORE || PORTABLE using IConvertible = Newtonsoft.Json.Utilities.Convertible; using ICustomAttributeProvider = Newtonsoft.Json.Utilities.CustomAttributeProvider; #endif @@ -44,6 +44,32 @@ using Newtonsoft.Json.Serialization; namespace Newtonsoft.Json.Utilities { +#if NETFX_CORE || PORTABLE + internal enum MemberTypes + { + Property, + Field, + Event, + Method, + Other + } + + internal class CustomAttributeProvider + { + private readonly object _underlyingObject; + + public CustomAttributeProvider(object o) + { + _underlyingObject = o; + } + + public object UnderlyingObject + { + get { return _underlyingObject; } + } + } +#endif + #if NETFX_CORE internal enum TypeCode { @@ -66,15 +92,6 @@ namespace Newtonsoft.Json.Utilities Decimal } - internal enum MemberTypes - { - Property, - Field, - Event, - Method, - Other - } - [Flags] internal enum BindingFlags { @@ -99,21 +116,6 @@ namespace Newtonsoft.Json.Utilities OptionalParamBinding = 262144, IgnoreReturn = 16777216 } - - internal class CustomAttributeProvider - { - private readonly object _underlyingObject; - - public CustomAttributeProvider(object o) - { - _underlyingObject = o; - } - - public object UnderlyingObject - { - get { return _underlyingObject; } - } - } #endif internal static class ReflectionUtils @@ -122,7 +124,7 @@ namespace Newtonsoft.Json.Utilities static ReflectionUtils() { -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) EmptyTypes = Type.EmptyTypes; #else EmptyTypes = new Type[0]; @@ -131,7 +133,7 @@ namespace Newtonsoft.Json.Utilities public static ICustomAttributeProvider GetCustomAttributeProvider(this object o) { -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) return (ICustomAttributeProvider)o; #else return new ICustomAttributeProvider(o); @@ -274,7 +276,7 @@ namespace Newtonsoft.Json.Utilities if (nonPublic) bindingFlags = bindingFlags | BindingFlags.NonPublic; - return t.GetConstructor(bindingFlags, null, ReflectionUtils.EmptyTypes, null); + return t.GetConstructors(bindingFlags).SingleOrDefault(c => !c.GetParameters().Any()); } public static bool IsNullable(Type t) @@ -705,30 +707,44 @@ namespace Newtonsoft.Json.Utilities return attributes.SingleOrDefault(); } -#if !NETFX_CORE +#if !(NETFX_CORE) public static T[] GetAttributes(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute { ValidationUtils.ArgumentNotNull(attributeProvider, "attributeProvider"); + object provider; + +#if !PORTABLE + provider = attributeProvider; +#else + provider = attributeProvider.UnderlyingObject; +#endif + // http://hyperthink.net/blog/getcustomattributes-gotcha/ // ICustomAttributeProvider doesn't do inheritance - if (attributeProvider is Type) - return (T[])((Type)attributeProvider).GetCustomAttributes(typeof(T), inherit); + if (provider is Type) + return (T[])((Type)provider).GetCustomAttributes(typeof(T), inherit); - if (attributeProvider is Assembly) - return (T[])Attribute.GetCustomAttributes((Assembly)attributeProvider, typeof(T), inherit); + if (provider is Assembly) + return (T[])Attribute.GetCustomAttributes((Assembly)provider, typeof(T)); - if (attributeProvider is MemberInfo) - return (T[])Attribute.GetCustomAttributes((MemberInfo)attributeProvider, typeof(T), inherit); + if (provider is MemberInfo) + return (T[])Attribute.GetCustomAttributes((MemberInfo)provider, typeof(T), inherit); - if (attributeProvider is Module) - return (T[])Attribute.GetCustomAttributes((Module)attributeProvider, typeof(T), inherit); +#if !PORTABLE + if (provider is Module) + return (T[])Attribute.GetCustomAttributes((Module)provider, typeof(T), inherit); +#endif - if (attributeProvider is ParameterInfo) - return (T[])Attribute.GetCustomAttributes((ParameterInfo)attributeProvider, typeof(T), inherit); + if (provider is ParameterInfo) + return (T[])Attribute.GetCustomAttributes((ParameterInfo)provider, typeof(T), inherit); +#if !PORTABLE return (T[])attributeProvider.GetCustomAttributes(typeof(T), inherit); +#else + throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider)); +#endif } #else public static T[] GetAttributes(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute @@ -981,8 +997,9 @@ namespace Newtonsoft.Json.Utilities public static bool IsMethodOverridden(Type currentType, Type methodDeclaringType, string method) { - bool isMethodOverriden = currentType.GetMember(method, MemberTypes.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Cast() + bool isMethodOverriden = currentType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Any(info => + info.Name == method && // check that the method overrides the original on DynamicObjectProxy info.DeclaringType != methodDeclaringType // todo - find out whether there is a way to do this in winrt diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index e744b46c..74b6d55d 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -141,7 +141,7 @@ namespace Newtonsoft.Json.Utilities return s; string camelCase = null; -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) camelCase = char.ToLower(s[0], CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); #else camelCase = char.ToLower(s[0]).ToString(); @@ -155,7 +155,7 @@ namespace Newtonsoft.Json.Utilities public static bool IsHighSurrogate(char c) { -#if !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) return char.IsHighSurrogate(c); #else return (c >= 55296 && c <= 56319); @@ -164,7 +164,7 @@ namespace Newtonsoft.Json.Utilities public static bool IsLowSurrogate(char c) { -#if !SILVERLIGHT +#if !(SILVERLIGHT || PORTABLE) return char.IsLowSurrogate(c); #else return (c >= 56320 && c <= 57343); diff --git a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs index f3cb74b6..954dbaae 100644 --- a/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs +++ b/Src/Newtonsoft.Json/Utilities/TypeExtensions.cs @@ -55,7 +55,7 @@ namespace Newtonsoft.Json.Utilities public static MemberTypes MemberType(this MemberInfo memberInfo) { -#if !NETFX_CORE +#if !(NETFX_CORE || PORTABLE) return memberInfo.MemberType; #else if (memberInfo is PropertyInfo) @@ -71,6 +71,7 @@ namespace Newtonsoft.Json.Utilities #endif } +#if !PORTABLE public static Module Module(this Type type) { #if !NETFX_CORE @@ -79,6 +80,7 @@ namespace Newtonsoft.Json.Utilities return type.GetTypeInfo().Module; #endif } +#endif public static bool ContainsGenericParameters(this Type type) { @@ -152,6 +154,41 @@ namespace Newtonsoft.Json.Utilities #endif } +#if PORTABLE + public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList indexParameters, object placeholder2) + { + IList propertyInfos = type.GetProperties(bindingFlags); + + return propertyInfos.Where(p => + { + if (name != null && name != p.Name) + return false; + if (propertyType != null && propertyType != p.PropertyType) + return false; + if (indexParameters != null) + { + if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters)) + return false; + } + + return true; + }).SingleOrDefault(); + } + + public static IEnumerable GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags) + { + return type.GetMembers(bindingFlags).Where(m => + { + if (name != null && name != m.Name) + return false; + if (m.MemberType() != memberType) + return false; + + return true; + }); + } +#endif + #if NETFX_CORE public static bool IsDefined(this Type type, Type attributeType, bool inherit) { @@ -168,39 +205,6 @@ namespace Newtonsoft.Json.Utilities return type.GetTypeInfo().GetDeclaredMethod(name); } - public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList indexParameters, object placeholder2) - { - return type.GetTypeInfo().DeclaredProperties.Where(p => - { - if (name != null && name != p.Name) - return false; - if (propertyType != null && propertyType != p.PropertyType) - return false; - if (indexParameters != null) - { - if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters)) - return false; - } - - return true; - }).SingleOrDefault(); - } - - public static IEnumerable GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags) - { - return type.GetTypeInfo().GetMembersRecursive().Where(m => - { - if (name != null && name != m.Name) - return false; - if (m.MemberType() != memberType) - return false; - if (!TestAccessibility(m, bindingFlags)) - return false; - - return true; - }); - } - public static MethodInfo GetMethod(this Type type, IList parameterTypes) { return type.GetMethod(null, parameterTypes); @@ -225,6 +229,39 @@ namespace Newtonsoft.Json.Utilities }).SingleOrDefault(); } + public static PropertyInfo GetProperty(this Type type, string name, BindingFlags bindingFlags, object placeholder1, Type propertyType, IList indexParameters, object placeholder2) + { + return type.GetTypeInfo().DeclaredProperties.Where(p => + { + if (name != null && name != p.Name) + return false; + if (propertyType != null && propertyType != p.PropertyType) + return false; + if (indexParameters != null) + { + if (!p.GetIndexParameters().Select(ip => ip.ParameterType).SequenceEqual(indexParameters)) + return false; + } + + return true; + }).SingleOrDefault(); + } + + public static IEnumerable GetMember(this Type type, string name, MemberTypes memberType, BindingFlags bindingFlags) + { + return type.GetTypeInfo().GetMembersRecursive().Where(m => + { + if (name != null && name != m.Name) + return false; + if (m.MemberType() != memberType) + return false; + if (!TestAccessibility(m, bindingFlags)) + return false; + + return true; + }); + } + public static IEnumerable GetConstructors(this Type type) { return type.GetConstructors(DefaultFlags);