当前位置: 首页>>代码示例>>C#>>正文


C# JSchema.WriteTo方法代码示例

本文整理汇总了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
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:19,代码来源:SaveJsonSchemaToFile.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:19,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:49,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:19,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:17,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:24,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:19,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:31,代码来源:JSchemaWriterTests.cs

示例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);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:43,代码来源:JSchemaWriterTests.cs


注:本文中的JSchema.WriteTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。