diff --git a/Src/Doc/Introduction.html b/Src/Doc/Introduction.html index e8a0df02..108cdbbb 100644 --- a/Src/Doc/Introduction.html +++ b/Src/Doc/Introduction.html @@ -17,13 +17,20 @@

Features

+

The JSON serializer is a good choice when the JSON you are reading or writing maps closely + to a .NET class. The serializer automatically reads and writes JSON for the class.

+

+ For situations where you are only interested in getting values from JSON, don't + have a class to serialize or deserialize to, or the JSON is radically different + from your class and you need to manually read and write from your objects then + LINQ to JSON is what you should use. LINQ to JSON allows you to easily read, + create and modify JSON in .NET.

History

diff --git a/Src/Doc/SerializingCollections.html b/Src/Doc/SerializingCollections.html new file mode 100644 index 00000000..7e1dc7b3 --- /dev/null +++ b/Src/Doc/SerializingCollections.html @@ -0,0 +1,128 @@ + + + + Serializing Collections + + + + + + +

+ Json.NET - Quick Starts & API Documentation
+ Serializing Collections
+ +
+ + +

The JsonSerializer has + great support for serializing and deserializing collections of objects.

+ +

Serializing

+

To serialize a collection - a generic list, array, dictionary, or your own custom collection - simply call the serializer with the object you want to get JSON for. + Json.NET will serialize the collection and all of the values it contains.

+ + +
+ +
+
Product p1 = new Product
+
  {
+
    Name = "Product 1",
+
    Price = 99.95m,
+
    ExpiryDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
+
  };
+
Product p2 = new Product
+
{
+
  Name = "Product 2",
+
  Price = 12.50m,
+
  ExpiryDate = new DateTime(2009, 7, 31, 0, 0, 0, DateTimeKind.Utc),
+
};
+
 
+
List<Product> products = new List<Product>();
+
products.Add(p1);
+
products.Add(p2);
+
 
+
string json = JsonConvert.SerializeObject(products, Formatting.Indented);
+
//[
+
//  {
+
//    "Name": "Product 1",
+
//    "ExpiryDate": "\/Date(978048000000)\/",
+
//    "Price": 99.95,
+
//    "Sizes": null
+
//  },
+
//  {
+
//    "Name": "Product 2",
+
//    "ExpiryDate": "\/Date(1248998400000)\/",
+
//    "Price": 12.50,
+
//    "Sizes": null
+
//  }
+
//]
+
+ +
+ +

Deserializing

+

To deserialize JSON into a .NET collection just specify the collection type you want to deserialize to. Json.NET supports a wide range of collection types.

+ +
+ +
+
string json = @"[
+
  {
+
    ""Name"": ""Product 1"",
+
    ""ExpiryDate"": ""\/Date(978048000000)\/"",
+
    ""Price"": 99.95,
+
    ""Sizes"": null
+
  },
+
  {
+
    ""Name"": ""Product 2"",
+
    ""ExpiryDate"": ""\/Date(1248998400000)\/"",
+
    ""Price"": 12.50,
+
    ""Sizes"": null
+
  }
+
]";
+
 
+
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(json);
+
 
+
Console.WriteLine(products.Count);
+
// 2
+
 
+
Product p1 = products[0];
+
 
+
Console.WriteLine(p1.Name);
+
// Product 1
+
+ +
+ +

Deserializing Dictionaries

+ +

Using Json.NET you can also deserialize a JSON object into a .NET generic dictionary. The JSON object's property names and values will be added to the dictionary.

+ +
+ +
+
string json = @"{""key1"":""value1"",""key2"":""value2""}";
+
 
+
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
+
 
+
Console.WriteLine(values.Count);
+
// 2
+
 
+
Console.WriteLine(values["key1"]);
+
// value1
+
+ +
+ + +
+ + + + \ No newline at end of file diff --git a/Src/Doc/doc.shfb b/Src/Doc/doc.shfb index d6ba72b3..543b5e5c 100644 --- a/Src/Doc/doc.shfb +++ b/Src/Doc/doc.shfb @@ -24,6 +24,7 @@ + Summary, Parameter, Returns, AutoDocumentCtors, Namespace, TypeParameter diff --git a/Src/Doc/doc.sitemap b/Src/Doc/doc.sitemap index e0c17bfb..f00d7646 100644 --- a/Src/Doc/doc.sitemap +++ b/Src/Doc/doc.sitemap @@ -3,7 +3,8 @@ - + + diff --git a/Src/Lib/LinqBridge.dll b/Src/Lib/LinqBridge.dll new file mode 100644 index 00000000..305c9bb4 Binary files /dev/null and b/Src/Lib/LinqBridge.dll differ diff --git a/Src/Newtonsoft.Json.Net20.sln b/Src/Newtonsoft.Json.Net20.sln new file mode 100644 index 00000000..3e5ce173 --- /dev/null +++ b/Src/Newtonsoft.Json.Net20.sln @@ -0,0 +1,33 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{620042D9-2753-48F5-BEDE-3905248781D2}" + ProjectSection(SolutionItems) = preProject + Lib\LinqBridge.dll = Lib\LinqBridge.dll + Lib\nunit.framework.dll = Lib\nunit.framework.dll + Lib\nunit.framework.xml = Lib\nunit.framework.xml + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Net20", "Newtonsoft.Json\Newtonsoft.Json.Net20.csproj", "{A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Tests.Net20", "Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Net20.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 + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}.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 daf2c921..1af3384d 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/BinaryConverterTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 using System.Data.Linq; #endif #if !SILVERLIGHT @@ -24,7 +24,7 @@ namespace Newtonsoft.Json.Tests.Converters public byte[] NullByteArray { get; set; } } -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 [Test] public void DeserializeBinaryClass() { diff --git a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs index 7424f73a..00c2f086 100644 --- a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 using System.ComponentModel.DataAnnotations; #endif using System.Text; @@ -39,7 +39,7 @@ using System.Collections.ObjectModel; using Newtonsoft.Json.Linq; using System.Linq; using Newtonsoft.Json.Converters; -#if !PocketPC +#if !PocketPC && !NET20 using System.Runtime.Serialization.Json; #endif using Newtonsoft.Json.Tests.TestObjects; @@ -473,7 +473,7 @@ keyword such as type of business."" Assert.AreEqual("Large", deserializedProductShort.Sizes[2]); } -#if !PocketPC +#if !PocketPC && !NET20 [Test] public void Unicode() { @@ -1542,7 +1542,7 @@ keyword such as type of business."" Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]); } -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 [MetadataType(typeof(OptInClassMetadata))] public class OptInClass { @@ -1587,7 +1587,7 @@ keyword such as type of business."" } #endif -#if !PocketPC +#if !PocketPC && !NET20 [DataContract] public class DataContractPrivateMembers { @@ -1938,5 +1938,107 @@ keyword such as type of business."" Assert.AreEqual(1, ((JObject)o.Data[2]).Count); Assert.AreEqual(1, (int)((JObject)o.Data[2])["one"]); } + + [Test] + public void DeserializeGenericDictionary() + { + string json = @"{""key1"":""value1"",""key2"":""value2""}"; + + Dictionary values = JsonConvert.DeserializeObject>(json); + + Console.WriteLine(values.Count); + // 2 + + Console.WriteLine(values["key1"]); + // value1 + + Assert.AreEqual(2, values.Count); + Assert.AreEqual("value1", values["key1"]); + Assert.AreEqual("value2", values["key2"]); + } + + [Test] + public void SerializeGenericList() + { + Product p1 = new Product + { + Name = "Product 1", + Price = 99.95m, + ExpiryDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc), + }; + Product p2 = new Product + { + Name = "Product 2", + Price = 12.50m, + ExpiryDate = new DateTime(2009, 7, 31, 0, 0, 0, DateTimeKind.Utc), + }; + + List products = new List(); + products.Add(p1); + products.Add(p2); + + string json = JsonConvert.SerializeObject(products, Formatting.Indented); + //[ + // { + // "Name": "Product 1", + // "ExpiryDate": "\/Date(978048000000)\/", + // "Price": 99.95, + // "Sizes": null + // }, + // { + // "Name": "Product 2", + // "ExpiryDate": "\/Date(1248998400000)\/", + // "Price": 12.50, + // "Sizes": null + // } + //] + + Assert.AreEqual(@"[ + { + ""Name"": ""Product 1"", + ""ExpiryDate"": ""\/Date(978048000000)\/"", + ""Price"": 99.95, + ""Sizes"": null + }, + { + ""Name"": ""Product 2"", + ""ExpiryDate"": ""\/Date(1248998400000)\/"", + ""Price"": 12.50, + ""Sizes"": null + } +]", json); + } + + [Test] + public void DeserializeGenericList() + { + string json = @"[ + { + ""Name"": ""Product 1"", + ""ExpiryDate"": ""\/Date(978048000000)\/"", + ""Price"": 99.95, + ""Sizes"": null + }, + { + ""Name"": ""Product 2"", + ""ExpiryDate"": ""\/Date(1248998400000)\/"", + ""Price"": 12.50, + ""Sizes"": null + } + ]"; + + List products = JsonConvert.DeserializeObject>(json); + + Console.WriteLine(products.Count); + // 2 + + Product p1 = products[0]; + + Console.WriteLine(p1.Name); + // Product 1 + + Assert.AreEqual(2, products.Count); + Assert.AreEqual("Product 1", products[0].Name); + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj index 3df20233..c7957baf 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj @@ -7,7 +7,7 @@ {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A} Library Properties - Newtonsoft.Json.Tests.Compact + Newtonsoft.Json.Tests Newtonsoft.Json.Tests.Compact {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} PocketPC @@ -24,7 +24,7 @@ full false bin\Debug\ - DEBUG;TRACE;$(PlatformFamilyName) + TRACE;DEBUG;PocketPC true true prompt diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj new file mode 100644 index 00000000..bf45f0a2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Net20.csproj @@ -0,0 +1,176 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3E6E2335-B079-4B5B-A65A-9D586914BCBB} + Library + Properties + Newtonsoft.Json.Tests + Newtonsoft.Json.Tests.Net20 + + + + + + + + + + + 2.0 + + + v2.0 + false + + + + + + + true + full + false + bin\Debug\ + TRACE;DEBUG;NET20 + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\Lib\LinqBridge.dll + + + False + ..\Lib\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D} + Newtonsoft.Json.Net20 + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj index a6547f9c..e644b76d 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Silverlight.csproj @@ -65,6 +65,8 @@ + + diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index fdc76e27..7bb208aa 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -1,4 +1,4 @@ -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 using System; using System.Collections.Generic; using System.Globalization; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/EntitiesSerializationTests.cs index 5c40037d..2150e6ee 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 !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 using System; using System.Collections.Generic; using System.Data; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs index 9ff471f8..e0b018e0 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 using System; using System.Collections.Generic; using System.IO; diff --git a/Src/Newtonsoft.Json.sln b/Src/Newtonsoft.Json.sln index e5baa538..5414e8fa 100644 --- a/Src/Newtonsoft.Json.sln +++ b/Src/Newtonsoft.Json.sln @@ -26,6 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Doc", "Doc", "{8F9E13D9-418 Doc\ReadingWritingJSON.html = Doc\ReadingWritingJSON.html Doc\SerializationAttributes.html = Doc\SerializationAttributes.html Doc\SerializationCallbacks.html = Doc\SerializationCallbacks.html + Doc\SerializingCollections.html = Doc\SerializingCollections.html Doc\SerializingJSON.html = Doc\SerializingJSON.html Doc\styles.css = Doc\styles.css EndProjectSection diff --git a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs index 354b48f3..32e159de 100644 --- a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs +++ b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 using System.Data.Linq; #endif #if !SILVERLIGHT @@ -67,7 +67,7 @@ namespace Newtonsoft.Json.Converters private byte[] GetByteArray(object value) { -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 if (value is Binary) return ((Binary)value).ToArray(); #endif @@ -109,11 +109,11 @@ namespace Newtonsoft.Json.Converters if (t == typeof(byte[])) return data; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 if (typeof(Binary).IsAssignableFrom(t)) return new Binary(data); #endif -#if !SILVERLIGHT +#if !SILVERLIGHT if (typeof(SqlBinary).IsAssignableFrom(t)) return new SqlBinary(data); #endif @@ -136,7 +136,7 @@ namespace Newtonsoft.Json.Converters if (t == typeof(byte[])) return true; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 if (typeof(Binary).IsAssignableFrom(t)) return true; #endif diff --git a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs index 84943966..031f3101 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 +#if !PocketPC && !SILVERLIGHT && !NET20 using System; using System.Collections.Generic; using System.Linq; diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index ae1b1532..d62395e5 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -24,13 +24,8 @@ #endregion using System; -using System.Collections.Generic; -using System.Text; -using System.Collections; using System.IO; using System.Globalization; -using System.Runtime.Serialization; -using System.Reflection; using Newtonsoft.Json.Utilities; using System.Xml; using Newtonsoft.Json.Converters; @@ -95,27 +90,27 @@ namespace Newtonsoft.Json } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(DateTime value) { TimeSpan utcOffset; -#if PocketPC - utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(value); -#else +#if !PocketPC && !NET20 utcOffset = TimeZoneInfo.Local.GetUtcOffset(value); +#else + utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(value); #endif return ToStringInternal(value, utcOffset, value.Kind); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(DateTimeOffset value) { return ToStringInternal(value.UtcDateTime, value.Offset, DateTimeKind.Local); @@ -143,10 +138,7 @@ namespace Newtonsoft.Json { DateTime utcDateTime = dateTime.ToUniversalTime(); - //if (utcDateTime < MinimumJavaScriptDate) - // utcDateTime = MinimumJavaScriptDate; - - long javaScriptTicks = (utcDateTime.Ticks - InitialJavaScriptDateTicks) / (long)10000; + long javaScriptTicks = (utcDateTime.Ticks - InitialJavaScriptDateTicks) / 10000; return javaScriptTicks; } @@ -159,110 +151,110 @@ namespace Newtonsoft.Json } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(bool value) { return (value) ? True : False; } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(char value) { return ToString(char.ToString(value)); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(Enum value) { return value.ToString("D"); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(int value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(short value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(ushort value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(uint value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(long value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(ulong value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(float value) { return EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(double value) { return EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture)); @@ -285,80 +277,79 @@ namespace Newtonsoft.Json } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(byte value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(sbyte value) { return value.ToString(null, CultureInfo.InvariantCulture); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(decimal value) { return EnsureDecimalPlace(value.ToString(null, CultureInfo.InvariantCulture)); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(Guid value) { return '"' + value.ToString("D", CultureInfo.InvariantCulture) + '"'; } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(string value) { return ToString(value, '"'); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. /// The string delimiter character. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(string value, char delimter) { return JavaScriptUtils.ToEscapedJavaScriptString(value, delimter, true); } /// - /// Converts the to it's JavaScript string representation. + /// Converts the to its JSON string representation. /// /// The value to convert. - /// A Json string representation of the . + /// A JSON string representation of the . public static string ToString(object value) { if (value == null) - { return Null; - } - else if (value is IConvertible) + + if (value is IConvertible) { - IConvertible convertible = value as IConvertible; + IConvertible convertible = (IConvertible)value; switch (convertible.GetTypeCode()) { @@ -407,12 +398,11 @@ namespace Newtonsoft.Json internal static bool IsJsonPrimitive(object value) { if (value == null) - { return true; - } - else if (value is IConvertible) + + if (value is IConvertible) { - IConvertible convertible = value as IConvertible; + IConvertible convertible = (IConvertible)value; switch (convertible.GetTypeCode()) { @@ -437,10 +427,9 @@ namespace Newtonsoft.Json return false; } } - else if (value is DateTimeOffset) - { + + if (value is DateTimeOffset) return true; - } return false; } diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 3fb5503b..76309c9c 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -54,7 +54,7 @@ namespace Newtonsoft.Json private static readonly IList BuiltInConverters = new List { -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 new EntityKeyMemberConverter() #endif }; diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index bcf0358a..0899c2d2 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -268,7 +268,7 @@ namespace Newtonsoft.Json if (schema.Enum != null) { - if (!schema.Enum.Contains(value, new JTokenEqualityComparer())) + if (!schema.Enum.ContainsValue(value, new JTokenEqualityComparer())) RaiseError("Value {0} is not defined in enum.".FormatWith(CultureInfo.InvariantCulture, value), schema); } diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index d564efe1..01d435e5 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -217,7 +217,7 @@ namespace Newtonsoft.Json.Linq else if (value is bool) return JTokenType.Boolean; - throw new ArgumentException("Could not determin JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType())); + throw new ArgumentException("Could not determine JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType())); } private static JTokenType GetStringValueType(JTokenType? current) diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj index 09b9b7ff..c44903bf 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj @@ -7,7 +7,7 @@ {256AA604-F61B-4B6D-8D51-C8E6AB11E435} Library Properties - Newtonsoft.Json.Compact + Newtonsoft.Json Newtonsoft.Json.Compact {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} PocketPC @@ -31,6 +31,8 @@ 512 4 Off + + pdbonly @@ -43,7 +45,7 @@ 512 4 Off - bin\Release\Newtonsoft.Json.Compact.XML + bin\Release\Newtonsoft.Json.Compact.xml diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj new file mode 100644 index 00000000..e8306d94 --- /dev/null +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net20.csproj @@ -0,0 +1,204 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D} + Library + Properties + Newtonsoft.Json + Newtonsoft.Json.Net20 + false + + + + + + + + + + + + + 2.0 + + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + v2.0 + + + + + true + full + false + bin\Debug\ + TRACE;DEBUG;NET20 + prompt + 4 + bin\Debug\Newtonsoft.Json.Net20.xml + true + -Microsoft.Design#CA1012;-Microsoft.Design#CA2210;-Microsoft.Design#CA1040;-Microsoft.Design#CA1005;-Microsoft.Design#CA1020;-Microsoft.Design#CA1021;-Microsoft.Design#CA1010;-Microsoft.Design#CA1011;-Microsoft.Design#CA1009;-Microsoft.Design#CA1050;-Microsoft.Design#CA1026;-Microsoft.Design#CA1019;-Microsoft.Design#CA1031;-Microsoft.Design#CA1047;-Microsoft.Design#CA1000;-Microsoft.Design#CA1048;-Microsoft.Design#CA1051;-Microsoft.Design#CA1002;-Microsoft.Design#CA1061;-Microsoft.Design#CA1006;-Microsoft.Design#CA1046;-Microsoft.Design#CA1045;-Microsoft.Design#CA1065;-Microsoft.Design#CA1038;-Microsoft.Design#CA1008;-Microsoft.Design#CA1028;-Microsoft.Design#CA1064;-Microsoft.Design#CA1004;-Microsoft.Design#CA1035;-Microsoft.Design#CA1063;-Microsoft.Design#CA1032;-Microsoft.Design#CA1023;-Microsoft.Design#CA1033;-Microsoft.Design#CA1039;-Microsoft.Design#CA1016;-Microsoft.Design#CA1014;-Microsoft.Design#CA1017;-Microsoft.Design#CA1018;-Microsoft.Design#CA1027;-Microsoft.Design#CA1059;-Microsoft.Design#CA1060;-Microsoft.Design#CA1034;-Microsoft.Design#CA1013;-Microsoft.Design#CA1036;-Microsoft.Design#CA1044;-Microsoft.Design#CA1041;-Microsoft.Design#CA1025;-Microsoft.Design#CA1052;-Microsoft.Design#CA1053;-Microsoft.Design#CA1057;-Microsoft.Design#CA1058;-Microsoft.Design#CA1001;-Microsoft.Design#CA1049;-Microsoft.Design#CA1054;-Microsoft.Design#CA1056;-Microsoft.Design#CA1055;-Microsoft.Design#CA1030;-Microsoft.Design#CA1003;-Microsoft.Design#CA1007;-Microsoft.Design#CA1043;-Microsoft.Design#CA1024;-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1302;-Microsoft.Globalization#CA1308;-Microsoft.Globalization#CA1306;-Microsoft.Globalization#CA2101;-Microsoft.Globalization#CA1300;-Microsoft.Globalization#CA1307;-Microsoft.Globalization#CA1309;-Microsoft.Interoperability#CA1403;-Microsoft.Interoperability#CA1406;-Microsoft.Interoperability#CA1413;-Microsoft.Interoperability#CA1402;-Microsoft.Interoperability#CA1407;-Microsoft.Interoperability#CA1404;-Microsoft.Interoperability#CA1410;-Microsoft.Interoperability#CA1411;-Microsoft.Interoperability#CA1405;-Microsoft.Interoperability#CA1409;-Microsoft.Interoperability#CA1415;-Microsoft.Interoperability#CA1408;-Microsoft.Interoperability#CA1414;-Microsoft.Interoperability#CA1412;-Microsoft.Interoperability#CA1400;-Microsoft.Interoperability#CA1401;-Microsoft.Maintainability#CA1506;-Microsoft.Maintainability#CA1502;-Microsoft.Maintainability#CA1501;-Microsoft.Maintainability#CA1505;-Microsoft.Maintainability#CA1504;-Microsoft.Maintainability#CA1500;-Microsoft.Mobility#CA1600;-Microsoft.Mobility#CA1601;-Microsoft.Naming#CA1702;-Microsoft.Naming#CA1700;-Microsoft.Naming#CA1712;-Microsoft.Naming#CA1713;-Microsoft.Naming#CA1714;-Microsoft.Naming#CA1709;-Microsoft.Naming#CA1704;-Microsoft.Naming#CA1708;-Microsoft.Naming#CA1715;-Microsoft.Naming#CA1710;-Microsoft.Naming#CA1720;-Microsoft.Naming#CA1707;-Microsoft.Naming#CA1722;-Microsoft.Naming#CA1711;-Microsoft.Naming#CA1716;-Microsoft.Naming#CA1717;-Microsoft.Naming#CA1725;-Microsoft.Naming#CA1719;-Microsoft.Naming#CA1721;-Microsoft.Naming#CA1701;-Microsoft.Naming#CA1703;-Microsoft.Naming#CA1724;-Microsoft.Naming#CA1726;-Microsoft.Performance#CA1809;-Microsoft.Performance#CA1811;-Microsoft.Performance#CA1812;-Microsoft.Performance#CA1813;-Microsoft.Performance#CA1823;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Performance#CA1810;-Microsoft.Performance#CA1824;-Microsoft.Performance#CA1822;-Microsoft.Performance#CA1815;-Microsoft.Performance#CA1814;-Microsoft.Performance#CA1819;-Microsoft.Performance#CA1821;-Microsoft.Performance#CA1804;-Microsoft.Performance#CA1820;-Microsoft.Performance#CA1802;-Microsoft.Portability#CA1901;-Microsoft.Portability#CA1900;-Microsoft.Reliability#CA2001;-Microsoft.Reliability#CA2002;-Microsoft.Reliability#CA2003;-Microsoft.Reliability#CA2004;-Microsoft.Reliability#CA2006;-Microsoft.Security#CA2116;-Microsoft.Security#CA2117;-Microsoft.Security#CA2105;-Microsoft.Security#CA2115;-Microsoft.Security#CA2102;-Microsoft.Security#CA2104;-Microsoft.Security#CA2122;-Microsoft.Security#CA2114;-Microsoft.Security#CA2123;-Microsoft.Security#CA2111;-Microsoft.Security#CA2108;-Microsoft.Security#CA2107;-Microsoft.Security#CA2103;-Microsoft.Security#CA2118;-Microsoft.Security#CA2109;-Microsoft.Security#CA2119;-Microsoft.Security#CA2106;-Microsoft.Security#CA2112;-Microsoft.Security#CA2120;-Microsoft.Security#CA2121;-Microsoft.Security#CA2126;-Microsoft.Security#CA2124;-Microsoft.Security#CA2127;-Microsoft.Security#CA2128;-Microsoft.Security#CA2129;-Microsoft.Usage#CA2243;-Microsoft.Usage#CA2236;-Microsoft.Usage#CA1816;-Microsoft.Usage#CA2227;-Microsoft.Usage#CA2213;-Microsoft.Usage#CA2216;-Microsoft.Usage#CA2214;-Microsoft.Usage#CA2222;-Microsoft.Usage#CA1806;-Microsoft.Usage#CA2217;-Microsoft.Usage#CA2212;-Microsoft.Usage#CA2219;-Microsoft.Usage#CA2201;-Microsoft.Usage#CA2228;-Microsoft.Usage#CA2221;-Microsoft.Usage#CA2220;-Microsoft.Usage#CA2240;-Microsoft.Usage#CA2229;-Microsoft.Usage#CA2238;-Microsoft.Usage#CA2207;-Microsoft.Usage#CA2208;-Microsoft.Usage#CA2235;-Microsoft.Usage#CA2237;-Microsoft.Usage#CA2232;-Microsoft.Usage#CA2223;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2233;-Microsoft.Usage#CA2225;-Microsoft.Usage#CA2226;-Microsoft.Usage#CA2231;-Microsoft.Usage#CA2224;-Microsoft.Usage#CA2218;-Microsoft.Usage#CA2234;-Microsoft.Usage#CA2239;-Microsoft.Usage#CA2200;-Microsoft.Usage#CA1801;-Microsoft.Usage#CA2242;-Microsoft.Usage#CA2205;-Microsoft.Usage#CA2230 + + + pdbonly + true + bin\Release\ + TRACE;NET20 + prompt + 4 + bin\Release\Newtonsoft.Json.Net20.xml + + + + False + ..\Lib\LinqBridge.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + .NET Framework 2.0 %28x86%29 + true + + + False + .NET Framework 3.0 %28x86%29 + false + + + False + .NET Framework 3.5 + false + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj index 4d9d40b4..4cf3632b 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj @@ -8,7 +8,7 @@ {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} Library Properties - Newtonsoft.Json.Silverlight + Newtonsoft.Json Newtonsoft.Json.Silverlight v3.5 false @@ -25,7 +25,7 @@ true prompt 4 - Bin\Debug\Newtonsoft.Json.Silverlight.XML + Bin\Debug\Newtonsoft.Json.Silverlight.xml pdbonly @@ -36,7 +36,7 @@ true prompt 4 - Bin\Release\Newtonsoft.Json.Silverlight.XML + Bin\Release\Newtonsoft.Json.Silverlight.xml diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index f4a1afd6..9e7613e9 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -50,7 +50,7 @@ DEBUG;TRACE prompt 4 - bin\Debug\Newtonsoft.Json.XML + bin\Debug\Newtonsoft.Json.xml true -Microsoft.Design#CA1012;-Microsoft.Design#CA2210;-Microsoft.Design#CA1040;-Microsoft.Design#CA1005;-Microsoft.Design#CA1020;-Microsoft.Design#CA1021;-Microsoft.Design#CA1010;-Microsoft.Design#CA1011;-Microsoft.Design#CA1009;-Microsoft.Design#CA1050;-Microsoft.Design#CA1026;-Microsoft.Design#CA1019;-Microsoft.Design#CA1031;-Microsoft.Design#CA1047;-Microsoft.Design#CA1000;-Microsoft.Design#CA1048;-Microsoft.Design#CA1051;-Microsoft.Design#CA1002;-Microsoft.Design#CA1061;-Microsoft.Design#CA1006;-Microsoft.Design#CA1046;-Microsoft.Design#CA1045;-Microsoft.Design#CA1065;-Microsoft.Design#CA1038;-Microsoft.Design#CA1008;-Microsoft.Design#CA1028;-Microsoft.Design#CA1064;-Microsoft.Design#CA1004;-Microsoft.Design#CA1035;-Microsoft.Design#CA1063;-Microsoft.Design#CA1032;-Microsoft.Design#CA1023;-Microsoft.Design#CA1033;-Microsoft.Design#CA1039;-Microsoft.Design#CA1016;-Microsoft.Design#CA1014;-Microsoft.Design#CA1017;-Microsoft.Design#CA1018;-Microsoft.Design#CA1027;-Microsoft.Design#CA1059;-Microsoft.Design#CA1060;-Microsoft.Design#CA1034;-Microsoft.Design#CA1013;-Microsoft.Design#CA1036;-Microsoft.Design#CA1044;-Microsoft.Design#CA1041;-Microsoft.Design#CA1025;-Microsoft.Design#CA1052;-Microsoft.Design#CA1053;-Microsoft.Design#CA1057;-Microsoft.Design#CA1058;-Microsoft.Design#CA1001;-Microsoft.Design#CA1049;-Microsoft.Design#CA1054;-Microsoft.Design#CA1056;-Microsoft.Design#CA1055;-Microsoft.Design#CA1030;-Microsoft.Design#CA1003;-Microsoft.Design#CA1007;-Microsoft.Design#CA1043;-Microsoft.Design#CA1024;-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1302;-Microsoft.Globalization#CA1308;-Microsoft.Globalization#CA1306;-Microsoft.Globalization#CA2101;-Microsoft.Globalization#CA1300;-Microsoft.Globalization#CA1307;-Microsoft.Globalization#CA1309;-Microsoft.Interoperability#CA1403;-Microsoft.Interoperability#CA1406;-Microsoft.Interoperability#CA1413;-Microsoft.Interoperability#CA1402;-Microsoft.Interoperability#CA1407;-Microsoft.Interoperability#CA1404;-Microsoft.Interoperability#CA1410;-Microsoft.Interoperability#CA1411;-Microsoft.Interoperability#CA1405;-Microsoft.Interoperability#CA1409;-Microsoft.Interoperability#CA1415;-Microsoft.Interoperability#CA1408;-Microsoft.Interoperability#CA1414;-Microsoft.Interoperability#CA1412;-Microsoft.Interoperability#CA1400;-Microsoft.Interoperability#CA1401;-Microsoft.Maintainability#CA1506;-Microsoft.Maintainability#CA1502;-Microsoft.Maintainability#CA1501;-Microsoft.Maintainability#CA1505;-Microsoft.Maintainability#CA1504;-Microsoft.Maintainability#CA1500;-Microsoft.Mobility#CA1600;-Microsoft.Mobility#CA1601;-Microsoft.Naming#CA1702;-Microsoft.Naming#CA1700;-Microsoft.Naming#CA1712;-Microsoft.Naming#CA1713;-Microsoft.Naming#CA1714;-Microsoft.Naming#CA1709;-Microsoft.Naming#CA1704;-Microsoft.Naming#CA1708;-Microsoft.Naming#CA1715;-Microsoft.Naming#CA1710;-Microsoft.Naming#CA1720;-Microsoft.Naming#CA1707;-Microsoft.Naming#CA1722;-Microsoft.Naming#CA1711;-Microsoft.Naming#CA1716;-Microsoft.Naming#CA1717;-Microsoft.Naming#CA1725;-Microsoft.Naming#CA1719;-Microsoft.Naming#CA1721;-Microsoft.Naming#CA1701;-Microsoft.Naming#CA1703;-Microsoft.Naming#CA1724;-Microsoft.Naming#CA1726;-Microsoft.Performance#CA1809;-Microsoft.Performance#CA1811;-Microsoft.Performance#CA1812;-Microsoft.Performance#CA1813;-Microsoft.Performance#CA1823;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Performance#CA1810;-Microsoft.Performance#CA1824;-Microsoft.Performance#CA1822;-Microsoft.Performance#CA1815;-Microsoft.Performance#CA1814;-Microsoft.Performance#CA1819;-Microsoft.Performance#CA1821;-Microsoft.Performance#CA1804;-Microsoft.Performance#CA1820;-Microsoft.Performance#CA1802;-Microsoft.Portability#CA1901;-Microsoft.Portability#CA1900;-Microsoft.Reliability#CA2001;-Microsoft.Reliability#CA2002;-Microsoft.Reliability#CA2003;-Microsoft.Reliability#CA2004;-Microsoft.Reliability#CA2006;-Microsoft.Security#CA2116;-Microsoft.Security#CA2117;-Microsoft.Security#CA2105;-Microsoft.Security#CA2115;-Microsoft.Security#CA2102;-Microsoft.Security#CA2104;-Microsoft.Security#CA2122;-Microsoft.Security#CA2114;-Microsoft.Security#CA2123;-Microsoft.Security#CA2111;-Microsoft.Security#CA2108;-Microsoft.Security#CA2107;-Microsoft.Security#CA2103;-Microsoft.Security#CA2118;-Microsoft.Security#CA2109;-Microsoft.Security#CA2119;-Microsoft.Security#CA2106;-Microsoft.Security#CA2112;-Microsoft.Security#CA2120;-Microsoft.Security#CA2121;-Microsoft.Security#CA2126;-Microsoft.Security#CA2124;-Microsoft.Security#CA2127;-Microsoft.Security#CA2128;-Microsoft.Security#CA2129;-Microsoft.Usage#CA2243;-Microsoft.Usage#CA2236;-Microsoft.Usage#CA1816;-Microsoft.Usage#CA2227;-Microsoft.Usage#CA2213;-Microsoft.Usage#CA2216;-Microsoft.Usage#CA2214;-Microsoft.Usage#CA2222;-Microsoft.Usage#CA1806;-Microsoft.Usage#CA2217;-Microsoft.Usage#CA2212;-Microsoft.Usage#CA2219;-Microsoft.Usage#CA2201;-Microsoft.Usage#CA2228;-Microsoft.Usage#CA2221;-Microsoft.Usage#CA2220;-Microsoft.Usage#CA2240;-Microsoft.Usage#CA2229;-Microsoft.Usage#CA2238;-Microsoft.Usage#CA2207;-Microsoft.Usage#CA2208;-Microsoft.Usage#CA2235;-Microsoft.Usage#CA2237;-Microsoft.Usage#CA2232;-Microsoft.Usage#CA2223;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2233;-Microsoft.Usage#CA2225;-Microsoft.Usage#CA2226;-Microsoft.Usage#CA2231;-Microsoft.Usage#CA2224;-Microsoft.Usage#CA2218;-Microsoft.Usage#CA2234;-Microsoft.Usage#CA2239;-Microsoft.Usage#CA2200;-Microsoft.Usage#CA1801;-Microsoft.Usage#CA2242;-Microsoft.Usage#CA2205;-Microsoft.Usage#CA2230 @@ -61,7 +61,7 @@ TRACE prompt 4 - bin\Release\Newtonsoft.Json.XML + bin\Release\Newtonsoft.Json.xml diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index cf7a32cc..2bfd2394 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -29,6 +29,9 @@ using System.Security; [assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")] #elif PocketPC [assembly: AssemblyTitle("Newtonsoft Json.NET Compact")] +#elif NET20 +[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 2.0")] +[assembly: AllowPartiallyTrustedCallers] #else [assembly: AssemblyTitle("Newtonsoft Json.NET")] [assembly: AllowPartiallyTrustedCallers] @@ -40,6 +43,8 @@ using System.Security; [assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Silverlight")] #elif PocketPC [assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact")] +#elif NET20 +[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net20")] #else [assembly: InternalsVisibleTo("Newtonsoft.Json.Tests")] #endif diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 9a71bb16..482ea5bf 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -32,7 +32,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Serialization; using Newtonsoft.Json.Utilities; -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 using System.Data.Objects.DataClasses; #endif @@ -80,10 +80,10 @@ namespace Newtonsoft.Json.Serialization /// The serializable members for the type. protected virtual List GetSerializableMembers(Type objectType) { -#if !PocketPC +#if !PocketPC && !NET20 DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(objectType); #endif - + List defaultMembers = ReflectionUtils.GetFieldsAndProperties(objectType, DefaultMembersSearchFlags); List allMembers = ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); @@ -98,14 +98,14 @@ namespace Newtonsoft.Json.Serialization { if (JsonTypeReflector.GetAttribute(member) != null) serializableMembers.Add(member); -#if !PocketPC +#if !PocketPC && !NET20 else if (dataContractAttribute != null && JsonTypeReflector.GetAttribute(member) != null) serializableMembers.Add(member); #endif } } -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 // don't include EntityKey on entities objects... this is a bit hacky if (typeof(EntityObject).IsAssignableFrom(objectType)) serializableMembers = serializableMembers.Where(ShouldSerializeEntityMember).ToList(); @@ -114,7 +114,7 @@ namespace Newtonsoft.Json.Serialization return serializableMembers; } -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 private bool ShouldSerializeEntityMember(MemberInfo memberInfo) { PropertyInfo propertyInfo = memberInfo as PropertyInfo; @@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Serialization { contract.IsReference = containerAttribute._isReference; } -#if !PocketPC +#if !PocketPC && !NET20 else { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType); @@ -161,7 +161,7 @@ namespace Newtonsoft.Json.Serialization } #endif -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { Type prevAttributeType = null; @@ -231,7 +231,7 @@ namespace Newtonsoft.Json.Serialization return CreateObjectContract(objectType); } -#if !PocketPC && !SILVERLIGHT +#if !PocketPC && !SILVERLIGHT && !NET20 private static bool IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, ref Type prevAttributeType) { if (!method.IsDefined(attributeType, false)) @@ -301,7 +301,7 @@ namespace Newtonsoft.Json.Serialization JsonProperty property = new JsonProperty(); property.Member = member; -#if !PocketPC +#if !PocketPC && !NET20 DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(member.DeclaringType); DataMemberAttribute dataMemberAttribute; @@ -317,7 +317,7 @@ namespace Newtonsoft.Json.Serialization string mappedName; if (propertyAttribute != null && propertyAttribute.PropertyName != null) mappedName = propertyAttribute.PropertyName; -#if !PocketPC +#if !PocketPC && !NET20 else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) mappedName = dataMemberAttribute.Name; #endif @@ -328,7 +328,7 @@ namespace Newtonsoft.Json.Serialization if (propertyAttribute != null) property.Required = propertyAttribute.IsRequired; -#if !PocketPC +#if !PocketPC && !NET20 else if (dataMemberAttribute != null) property.Required = dataMemberAttribute.IsRequired; #endif @@ -338,10 +338,10 @@ namespace Newtonsoft.Json.Serialization property.Ignored = (hasIgnoreAttribute || (contract.MemberSerialization == MemberSerialization.OptIn && propertyAttribute == null -#if !PocketPC +#if !PocketPC && !NET20 && dataMemberAttribute == null #endif - )); +)); property.Readable = ReflectionUtils.CanReadMemberValue(member); property.Writable = ReflectionUtils.CanSetMemberValue(member); diff --git a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs index 8f3bc5e2..6694d52d 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs @@ -24,7 +24,7 @@ #endregion using System; -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 using System.ComponentModel.DataAnnotations; #endif using System.Globalization; @@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Serialization public const string ArrayValuesPropertyName = "$values"; private static readonly ThreadSafeStore ConverterTypeCache = new ThreadSafeStore(GetConverterTypeFromAttribute); -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 private static readonly ThreadSafeStore AssociatedMetadataTypesCache = new ThreadSafeStore(GetAssociateMetadataTypeFromAttribute); #endif @@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Serialization return GetJsonContainerAttribute(type) as JsonObjectAttribute; } -#if !PocketPC +#if !PocketPC && !NET20 public static DataContractAttribute GetDataContractAttribute(Type type) { return CachedAttributeGetter.GetAttribute(type); @@ -70,13 +70,13 @@ namespace Newtonsoft.Json.Serialization if (objectAttribute == null) { -#if !PocketPC +#if !PocketPC && !NET20 DataContractAttribute dataContractAttribute = GetDataContractAttribute(objectType); if (dataContractAttribute != null) return MemberSerialization.OptIn; #endif - + return MemberSerialization.OptOut; } @@ -113,7 +113,7 @@ namespace Newtonsoft.Json.Serialization return null; } -#if !SILVERLIGHT && !PocketPC +#if !SILVERLIGHT && !PocketPC && !NET20 private static Type GetAssociatedMetadataType(Type type) { return AssociatedMetadataTypesCache.Get(type); diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index 15feeb83..d6e03adc 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -580,13 +580,31 @@ namespace Newtonsoft.Json.Utilities public static bool AddDistinct(this IList list, T value, IEqualityComparer comparer) { - if (list.Contains(value, comparer)) + if (list.ContainsValue(value, comparer)) return false; list.Add(value); return true; } + // this is here because LINQ Bridge doesn't support Contains with IEqualityComparer + public static bool ContainsValue(this IEnumerable source, TSource value, IEqualityComparer comparer) + { + if (comparer == null) + comparer = EqualityComparer.Default; + + if (source == null) + throw new ArgumentNullException("source"); + + foreach (TSource local in source) + { + if (comparer.Equals(local, value)) + return true; + } + + return false; + } + public static bool AddRangeDistinct(this IList list, IEnumerable values) { return list.AddRangeDistinct(values, EqualityComparer.Default); diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs index cb4bf15b..21100cd8 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs @@ -12,7 +12,7 @@ namespace Newtonsoft.Json.Utilities public static string GetLocalOffset(this DateTime d) { TimeSpan utcOffset; -#if PocketPC +#if PocketPC || NET20 utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(d); #else utcOffset = TimeZoneInfo.Local.GetUtcOffset(d);