-Examples!

This commit is contained in:
James Newton-King
2013-01-28 00:07:21 +13:00
parent fd7970a3c3
commit 70ace8d527
115 changed files with 1120 additions and 210 deletions
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
JsonSchema schema = new JsonSchema();
schema.Type = JsonSchemaType.Object;
schema.Properties = new Dictionary<string, JsonSchema>
@@ -52,6 +53,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -34,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -42,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -41,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -1,32 +0,0 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public class JsonSchemaLoad
{
public void Example()
{
string schemaJson = @"{'type': 'object'}";
JsonSchema schema;
using (TextReader file = File.OpenText(@"c:\schema.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
schema = JsonSchema.Read(reader);
}
JObject o = JObject.Parse(@"{}");
bool valid = o.IsValid(schema);
Console.WriteLine(valid);
// true
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -34,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// name - String
// hobbies - Array
#endregion
}
}
}
@@ -9,14 +9,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public class JsonValidatingReaderAndSerializer
{
#region Types
public class Person
{
public string Name { get; set; }
public IList<string> Hobbies { get; set; }
}
#endregion
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -52,6 +55,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(isValid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
// read file into a string and parse JsonSchema from the string
JsonSchema schema1 = JsonSchema.Parse(File.ReadAllText(@"c:\schema.json"));
@@ -20,6 +21,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
JsonSchema schema2 = JsonSchema.Read(reader);
}
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson;
JsonSchemaResolver resolver = new JsonSchemaResolver();
@@ -50,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
JsonSchema schema = JsonSchema.Parse(@"{'type': 'object'}");
// serialize JsonSchema to a string and then write string to a file
@@ -22,6 +23,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
schema.WriteTo(writer);
}
#endregion
}
}
}