-Code reformat

This commit is contained in:
James Newton-King
2013-10-20 15:08:39 +13:00
parent d03963016e
commit bcd6982419
466 changed files with 71645 additions and 71598 deletions
@@ -7,53 +7,53 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class CreateJsonSchemaManually
{
public void Example()
public class CreateJsonSchemaManually
{
#region Usage
JsonSchema schema = new JsonSchema();
schema.Type = JsonSchemaType.Object;
schema.Properties = new Dictionary<string, JsonSchema>
public void Example()
{
{"name", new JsonSchema {Type = JsonSchemaType.String}},
{
"hobbies", new JsonSchema
{
Type = JsonSchemaType.Array,
Items = new List<JsonSchema> { new JsonSchema {Type = JsonSchemaType.String} }
}
},
};
#region Usage
JsonSchema schema = new JsonSchema();
schema.Type = JsonSchemaType.Object;
schema.Properties = new Dictionary<string, JsonSchema>
{
{ "name", new JsonSchema { Type = JsonSchemaType.String } },
{
"hobbies", new JsonSchema
{
Type = JsonSchemaType.Array,
Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } }
}
},
};
string schemaJson = schema.ToString();
string schemaJson = schema.ToString();
Console.WriteLine(schemaJson);
// {
// "type": "object",
// "properties": {
// "name": {
// "type": "string"
// },
// "hobbies": {
// "type": "array",
// "items": {
// "type": "string"
// }
// }
// }
// }
Console.WriteLine(schemaJson);
// {
// "type": "object",
// "properties": {
// "name": {
// "type": "string"
// },
// "hobbies": {
// "type": "array",
// "items": {
// "type": "string"
// }
// }
// }
// }
JObject person = JObject.Parse(@"{
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
bool valid = person.IsValid(schema);
bool valid = person.IsValid(schema);
Console.WriteLine(valid);
// true
#endregion
Console.WriteLine(valid);
// true
#endregion
}
}
}
}
@@ -7,33 +7,33 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JTokenIsValid
{
public void Example()
public class JTokenIsValid
{
#region Usage
JsonSchema schema = JsonSchema.Parse(@"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
public void Example()
{
#region Usage
JsonSchema schema = JsonSchema.Parse(@"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}");
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
bool valid = person.IsValid(schema);
Console.WriteLine(valid);
// true
#endregion
}
}");
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
bool valid = person.IsValid(schema);
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -7,43 +7,43 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JTokenIsValidWithMessages
{
public void Example()
public class JTokenIsValidWithMessages
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject person = JObject.Parse(@"{
'name': null,
'hobbies': ['Invalid content', 0.123456789]
}");
IList<string> messages;
bool valid = person.IsValid(schema, out messages);
Console.WriteLine(valid);
// false
foreach (string message in messages)
{
Console.WriteLine(message);
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject person = JObject.Parse(@"{
'name': null,
'hobbies': ['Invalid content', 0.123456789]
}");
IList<string> messages;
bool valid = person.IsValid(schema, out messages);
Console.WriteLine(valid);
// false
foreach (string message in messages)
{
Console.WriteLine(message);
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -7,42 +7,42 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JTokenValidateWithEvent
{
public void Example()
public class JTokenValidateWithEvent
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject person = JObject.Parse(@"{
'name': null,
'hobbies': ['Invalid content', 0.123456789]
}");
IList<string> messages = new List<string>();
ValidationEventHandler validationEventHandler = (sender, args) => { messages.Add(args.Message); };
person.Validate(schema, validationEventHandler);
foreach (string message in messages)
{
Console.WriteLine(message);
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject person = JObject.Parse(@"{
'name': null,
'hobbies': ['Invalid content', 0.123456789]
}");
IList<string> messages = new List<string>();
ValidationEventHandler validationEventHandler = (sender, args) => { messages.Add(args.Message); };
person.Validate(schema, validationEventHandler);
foreach (string message in messages)
{
Console.WriteLine(message);
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -7,35 +7,35 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JsonSchemaParse
{
public void Example()
public class JsonSchemaParse
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
Console.WriteLine(schema.Type);
// Object
foreach (var property in schema.Properties)
{
Console.WriteLine(property.Key + " - " + property.Value.Type);
}
// name - String
// hobbies - Array
#endregion
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
Console.WriteLine(schema.Type);
// Object
foreach (var property in schema.Properties)
{
Console.WriteLine(property.Key + " - " + property.Value.Type);
}
// name - String
// hobbies - Array
#endregion
}
}
}
@@ -7,55 +7,55 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JsonValidatingReaderAndSerializer
{
#region Types
public class Person
public class JsonValidatingReaderAndSerializer
{
public string Name { get; set; }
public IList<string> Hobbies { get; set; }
}
#endregion
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
#region Types
public class Person
{
public string Name { get; set; }
public IList<string> Hobbies { get; set; }
}
}";
#endregion
string json = @"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}";
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
string json = @"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}";
JsonValidatingReader validatingReader = new JsonValidatingReader(reader);
validatingReader.Schema = JsonSchema.Parse(schemaJson);
JsonTextReader reader = new JsonTextReader(new StringReader(json));
IList<string> messages = new List<string>();
validatingReader.ValidationEventHandler += (o, a) => messages.Add(a.Message);
JsonValidatingReader validatingReader = new JsonValidatingReader(reader);
validatingReader.Schema = JsonSchema.Parse(schemaJson);
JsonSerializer serializer = new JsonSerializer();
Person p = serializer.Deserialize<Person>(validatingReader);
IList<string> messages = new List<string>();
validatingReader.ValidationEventHandler += (o, a) => messages.Add(a.Message);
Console.WriteLine(p.Name);
// James
JsonSerializer serializer = new JsonSerializer();
Person p = serializer.Deserialize<Person>(validatingReader);
bool isValid = (messages.Count == 0);
Console.WriteLine(p.Name);
// James
Console.WriteLine(isValid);
// true
#endregion
bool isValid = (messages.Count == 0);
Console.WriteLine(isValid);
// true
#endregion
}
}
}
}
@@ -7,21 +7,21 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class LoadJsonSchemaFromFile
{
public void Example()
public class LoadJsonSchemaFromFile
{
#region Usage
// read file into a string and parse JsonSchema from the string
JsonSchema schema1 = JsonSchema.Parse(File.ReadAllText(@"c:\schema.json"));
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"));
// read JsonSchema directly from a file
using (StreamReader file = File.OpenText(@"c:\schema.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JsonSchema schema2 = JsonSchema.Read(reader);
}
#endregion
// read JsonSchema directly from a file
using (StreamReader file = File.OpenText(@"c:\schema.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JsonSchema schema2 = JsonSchema.Read(reader);
}
#endregion
}
}
}
}
@@ -7,51 +7,51 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class RefJsonSchemaResolver
{
public void Example()
public class RefJsonSchemaResolver
{
#region Usage
string schemaJson;
JsonSchemaResolver resolver = new JsonSchemaResolver();
public void Example()
{
#region Usage
string schemaJson;
JsonSchemaResolver resolver = new JsonSchemaResolver();
schemaJson = @"{
'id': 'person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'age': {'type':'integer'}
schemaJson = @"{
'id': 'person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'age': {'type':'integer'}
}
}";
JsonSchema personSchema = JsonSchema.Parse(schemaJson, resolver);
schemaJson = @"{
'id': 'employee',
'type': 'object',
'extends': {'$ref':'person'},
'properties': {
'salary': {'type':'number'},
'jobTitle': {'type':'string'}
}
}";
JsonSchema employeeSchema = JsonSchema.Parse(schemaJson, resolver);
string json = @"{
'name': 'James',
'age': 29,
'salary': 9000.01,
'jobTitle': 'Junior Vice President'
}";
JObject employee = JObject.Parse(json);
bool valid = employee.IsValid(employeeSchema);
Console.WriteLine(valid);
// true
#endregion
}
}";
JsonSchema personSchema = JsonSchema.Parse(schemaJson, resolver);
schemaJson = @"{
'id': 'employee',
'type': 'object',
'extends': {'$ref':'person'},
'properties': {
'salary': {'type':'number'},
'jobTitle': {'type':'string'}
}
}";
JsonSchema employeeSchema = JsonSchema.Parse(schemaJson, resolver);
string json = @"{
'name': 'James',
'age': 29,
'salary': 9000.01,
'jobTitle': 'Junior Vice President'
}";
JObject employee = JObject.Parse(json);
bool valid = employee.IsValid(employeeSchema);
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -7,26 +7,26 @@ using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class SaveJsonSchemaToFile
{
public void Example()
public class SaveJsonSchemaToFile
{
#region Usage
JsonSchema schema = new JsonSchema
public void Example()
{
Type = JsonSchemaType.Object
};
#region Usage
JsonSchema schema = new JsonSchema
{
Type = JsonSchemaType.Object
};
// serialize JsonSchema to a string and then write string to a file
File.WriteAllText(@"c:\schema.json", schema.ToString());
// serialize JsonSchema to a string and then write string to a file
File.WriteAllText(@"c:\schema.json", schema.ToString());
// serialize JsonSchema directly to a file
using (StreamWriter file = File.CreateText(@"c:\schema.json"))
using (JsonTextWriter writer = new JsonTextWriter(file))
{
schema.WriteTo(writer);
}
#endregion
// serialize JsonSchema directly to a file
using (StreamWriter file = File.CreateText(@"c:\schema.json"))
using (JsonTextWriter writer = new JsonTextWriter(file))
{
schema.WriteTo(writer);
}
#endregion
}
}
}
}