本文整理汇总了C#中JSchema.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# JSchema.WriteTo方法的具体用法?C# JSchema.WriteTo怎么用?C# JSchema.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSchema
的用法示例。
在下文中一共展示了JSchema.WriteTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Example
public void Example()
{
#region Usage
JSchema schema = new JSchema
{
Type = JSchemaType.Object
};
// serialize JSchema to a string and then write string to a file
File.WriteAllText(@"c:\schema.json", schema.ToString());
// serialize JSchema directly to a file
using (StreamWriter file = File.CreateText(@"c:\schema.json"))
using (JsonTextWriter writer = new JsonTextWriter(file))
{
schema.WriteTo(writer);
}
#endregion
}
示例2: WriteTo_Format
public void WriteTo_Format()
{
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
JSchema schema = new JSchema
{
Format = "a-format"
};
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""format"": ""a-format""
}", json);
}
示例3: WriteTo_ExternalResolvedReferenceInDefinition
public void WriteTo_ExternalResolvedReferenceInDefinition()
{
JSchema referenceSchema = new JSchema
{
Id = new Uri("http://localhost/test")
};
JSchema root = new JSchema
{
Id = new Uri("#root", UriKind.RelativeOrAbsolute),
Not = referenceSchema,
ExtensionData =
{
{
"definitions",
new JObject
{
{ "reference", referenceSchema }
}
}
}
};
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
root.WriteTo(jsonWriter, new JSchemaWriterSettings
{
ExternalSchemas = new List<ExternalSchema>
{
new ExternalSchema(referenceSchema)
}
});
string json = writer.ToString();
StringAssert.AreEqual(@"{
""id"": ""#root"",
""definitions"": {
""reference"": {
""$ref"": ""http://localhost/test""
}
},
""not"": {
""$ref"": ""http://localhost/test""
}
}", json);
}
示例4: WriteTo_PositionalItemsValidation_FalseWithItemsSchema
public void WriteTo_PositionalItemsValidation_FalseWithItemsSchema()
{
JSchema schema = new JSchema();
schema.Items.Add(new JSchema { Type = JSchemaType.String });
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""items"": {
""type"": ""string""
}
}", json);
}
示例5: WriteTo_PositionalItemsValidation_True
public void WriteTo_PositionalItemsValidation_True()
{
JSchema schema = new JSchema();
schema.ItemsPositionValidation = true;
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""items"": []
}", json);
}
示例6: WriteTo_PatternProperties
public void WriteTo_PatternProperties()
{
JSchema schema = new JSchema
{
PatternProperties =
{
{ "[abc]", new JSchema() }
}
};
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""patternProperties"": {
""[abc]"": {}
}
}", json);
}
示例7: WriteTo_ExclusiveMinimum_ExclusiveMaximum
public void WriteTo_ExclusiveMinimum_ExclusiveMaximum()
{
JSchema schema = new JSchema();
schema.ExclusiveMinimum = true;
schema.ExclusiveMaximum = true;
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""exclusiveMinimum"": true,
""exclusiveMaximum"": true
}", json);
}
示例8: WriteTo_Required
public void WriteTo_Required()
{
JSchema schema = new JSchema
{
Properties =
{
{ "prop1", new JSchema() }
},
Required =
{
"prop1"
}
};
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
schema.WriteTo(jsonWriter);
string json = writer.ToString();
StringAssert.AreEqual(@"{
""properties"": {
""prop1"": {}
},
""required"": [
""prop1""
]
}", json);
}
示例9: WriteTo_InnerSchemaOfExternalResolvedReference
public void WriteTo_InnerSchemaOfExternalResolvedReference()
{
JSchema nestedReference = new JSchema()
{
Type = JSchemaType.Boolean
};
JSchema referenceSchema = new JSchema
{
Id = new Uri("http://localhost/test"),
Items =
{
nestedReference
}
};
JSchema root = new JSchema
{
Id = new Uri("#root", UriKind.RelativeOrAbsolute),
Not = nestedReference
};
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
root.WriteTo(jsonWriter, new JSchemaWriterSettings
{
ExternalSchemas =
{
new ExternalSchema(referenceSchema)
}
});
string json = writer.ToString();
StringAssert.AreEqual(@"{
""id"": ""#root"",
""not"": {
""$ref"": ""http://localhost/test#/items/0""
}
}", json);
}