-Improved documentation

This commit is contained in:
James Newton-King
2012-07-27 22:57:08 +12:00
parent 2097219ec9
commit 29f1ed9cd0
18 changed files with 173 additions and 46 deletions
@@ -64,7 +64,7 @@ namespace Newtonsoft.Json.Tests.Documentation
string json = array.ToString();
// [
// "Manual text",
// "\/Date(958996800000+1200)\/"
// "2000-05-23T00:00:00"
// ]
#endregion
}
@@ -173,7 +173,7 @@ namespace Newtonsoft.Json.Tests.Documentation
CPU: 'Intel',
Drives: [
'DVD read/writer',
""500 gigabyte hard drive""
'500 gigabyte hard drive'
]
}";
@@ -181,6 +181,19 @@ namespace Newtonsoft.Json.Tests.Documentation
#endregion
}
public void LinqToJsonCreateParseArray()
{
#region LinqToJsonCreateParseArray
string json = @"[
'Small',
'Medium',
'Large'
]";
JArray a = JArray.Parse(json);
#endregion
}
public void LinqToJsonQuerying()
{
JObject rss = new JObject();
@@ -49,7 +49,8 @@ using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
namespace Newtonsoft.Json.Tests.Documentation
{
public class ReadingAndWritingJsonTests
[TestFixture]
public class ReadingAndWritingJsonTests : TestFixtureBase
{
public void ReadingAndWritingJsonText()
{
@@ -89,6 +90,46 @@ namespace Newtonsoft.Json.Tests.Documentation
#endregion
}
[Test]
public void ReadingJsonText()
{
#region ReadingJsonText
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
'Drives': [
'DVD read/writer'
/*(broken)*/,
'500 gigabyte hard drive',
'200 gigabype hard drive'
]
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
if (reader.Value != null)
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
else
Console.WriteLine("Token: {0}", reader.TokenType);
}
// Token: StartObject
// Token: PropertyName, Value: CPU
// Token: String, Value: Intel
// Token: PropertyName, Value: PSU
// Token: String, Value: 500W
// Token: PropertyName, Value: Drives
// Token: StartArray
// Token: String, Value: DVD read/writer
// Token: Comment, Value: (broken)
// Token: String, Value: 500 gigabyte hard drive
// Token: String, Value: 200 gigabype hard drive
// Token: EndArray
// Token: EndObject
#endregion
}
public void ReadingAndWritingJsonLinq()
{
#region ReadingAndWritingJsonLinq
@@ -332,13 +332,13 @@ namespace Newtonsoft.Json.Tests.Documentation
//[
// {
// "Name": "James",
// "BirthDate": "\/Date(346377600000)\/",
// "LastModified": "\/Date(1235134761000)\/"
// "BirthDate": "1980-12-23T00:00:00Z",
// "LastModified": "2009-02-20T12:59:21Z"
// },
// {
// "Name": "James",
// "BirthDate": "\/Date(346377600000)\/",
// "LastModified": "\/Date(1235134761000)\/"
// "BirthDate": "1980-12-23T00:00:00Z",
// "LastModified": "2009-02-20T12:59:21Z"
// }
//]
#endregion
@@ -356,8 +356,8 @@ namespace Newtonsoft.Json.Tests.Documentation
// {
// "$id": "1",
// "Name": "James",
// "BirthDate": "\/Date(346377600000)\/",
// "LastModified": "\/Date(1235134761000)\/"
// "BirthDate": "1983-03-08T00:00Z",
// "LastModified": "2012-03-21T05:40Z"
// },
// {
// "$ref": "1"
@@ -428,14 +428,14 @@ namespace Newtonsoft.Json.Tests.Documentation
// {
// "FirstName": "Maurice",
// "LastName": "Moss",
// "BirthDate": "\/Date(252291661000)\/",
// "BirthDate": "1981-03-08T00:00Z",
// "Department": "IT",
// "JobTitle": "Support"
// },
// {
// "FirstName": "Jen",
// "LastName": "Barber",
// "BirthDate": "\/Date(258771661000)\/",
// "BirthDate": "1985-12-10T00:00Z",
// "Department": "IT",
// "JobTitle": "Manager"
// }
@@ -478,7 +478,7 @@ namespace Newtonsoft.Json.Tests.Documentation
//{
// "name": "Widget",
// "expiryDate": "\/Date(1292868060000)\/",
// "expiryDate": "2010-12-20T18:01Z",
// "price": 9.99,
// "sizes": [
// "Small",
@@ -513,13 +513,13 @@ namespace Newtonsoft.Json.Tests.Documentation
//[
// {
// "Name": "Product 1",
// "ExpiryDate": "\/Date(978048000000)\/",
// "ExpiryDate": "2000-12-29T00:00Z",
// "Price": 99.95,
// "Sizes": null
// },
// {
// "Name": "Product 2",
// "ExpiryDate": "\/Date(1248998400000)\/",
// "ExpiryDate": "2009-07-31T00:00Z",
// "Price": 12.50,
// "Sizes": null
// }
@@ -533,13 +533,13 @@ namespace Newtonsoft.Json.Tests.Documentation
string json = @"[
{
'Name': 'Product 1',
'ExpiryDate': '\/Date(978048000000)\/',
'ExpiryDate': '2000-12-29T00:00Z',
'Price': 99.95,
'Sizes': null
},
{
'Name': 'Product 2',
'ExpiryDate': '\/Date(1248998400000)\/',
'ExpiryDate': '2009-07-31T00:00Z',
'Price': 12.50,
'Sizes': null
}
@@ -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.7.15122")]
[assembly: AssemblyFileVersion("4.5.7.15127")]
#endif
@@ -30,6 +30,10 @@ namespace Newtonsoft.Json
/// <summary>
/// Specifies default value handling options for the <see cref="JsonSerializer"/>.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeDefaultValueHandlingObject" title="DefaultValueHandling Class" />
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeDefaultValueHandlingExample" title="DefaultValueHandling Ignore Example" />
/// </example>
[Flags]
public enum DefaultValueHandling
{
+3
View File
@@ -45,6 +45,9 @@ namespace Newtonsoft.Json
/// <summary>
/// Provides methods for converting between common language runtime types and JSON types.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="SerializeObject" title="Serializing and Deserializing JSON with JsonConvert" />
/// </example>
public static class JsonConvert
{
/// <summary>
+6
View File
@@ -34,6 +34,9 @@ namespace Newtonsoft.Json.Linq
/// <summary>
/// Represents a JSON array.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParseArray" title="Parsing a JSON Array from Text" />
/// </example>
public class JArray : JContainer, IList<JToken>
{
private readonly IList<JToken> _values = new List<JToken>();
@@ -135,6 +138,9 @@ namespace Newtonsoft.Json.Linq
/// </summary>
/// <param name="json">A <see cref="String"/> that contains JSON.</param>
/// <returns>A <see cref="JArray"/> populated from the string that contains JSON.</returns>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParseArray" title="Parsing a JSON Array from Text" />
/// </example>
public static new JArray Parse(string json)
{
JsonReader reader = new JsonTextReader(new StringReader(json));
+6
View File
@@ -48,6 +48,9 @@ namespace Newtonsoft.Json.Linq
/// <summary>
/// Represents a JSON object.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParse" title="Parsing a JSON Object from Text" />
/// </example>
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
, ICustomTypeDescriptor
@@ -315,6 +318,9 @@ namespace Newtonsoft.Json.Linq
/// </summary>
/// <param name="json">A <see cref="String"/> that contains JSON.</param>
/// <returns>A <see cref="JObject"/> populated from the string that contains JSON.</returns>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParse" title="Parsing a JSON Object from Text" />
/// </example>
public static new JObject Parse(string json)
{
JsonReader reader = new JsonTextReader(new StringReader(json));
+4
View File
@@ -28,6 +28,10 @@ namespace Newtonsoft.Json
/// <summary>
/// Specifies null value handling options for the <see cref="JsonSerializer"/>.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeNullValueHandlingObject" title="NullValueHandling Class" />
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeNullValueHandlingExample" title="NullValueHandling Ignore Example" />
/// </example>
public enum NullValueHandling
{
/// <summary>
@@ -32,6 +32,9 @@ namespace Newtonsoft.Json
/// <summary>
/// Specifies reference handling options for the <see cref="JsonSerializer"/>.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="PreservingObjectReferencesOn" title="Preserve Object References" />
/// </example>
[Flags]
public enum PreserveReferencesHandling
{
@@ -90,7 +90,7 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.7.15122")]
[assembly: AssemblyFileVersion("4.5.7.15127")]
#endif
[assembly: CLSCompliant(true)]
@@ -30,6 +30,10 @@ namespace Newtonsoft.Json.Serialization
/// <summary>
/// Used by <see cref="JsonSerializer"/> to resolves a <see cref="JsonContract"/> for a given <see cref="Type"/>.
/// </summary>
/// <example>
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeContractResolverObject" title="IContractResolver Class" />
/// <code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeContractResolverExample" title="IContractResolver Example" />
/// </example>
public interface IContractResolver
{
/// <summary>