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


C# JSchema.ToString方法代码示例

本文整理汇总了C#中JSchema.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JSchema.ToString方法的具体用法?C# JSchema.ToString怎么用?C# JSchema.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSchema的用法示例。


在下文中一共展示了JSchema.ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteTo_ReferenceWithRootId

        public void WriteTo_ReferenceWithRootId()
        {
            JSchema nested = new JSchema
            {
                Type = JSchemaType.Object
            };

            JSchema s = new JSchema();
            s.Id = new Uri("http://www.jnk.com/");
            s.Items.Add(nested);
            s.Properties["test"] = nested;

            string json = s.ToString();

            StringAssert.AreEqual(@"{
  ""id"": ""http://www.jnk.com/"",
  ""properties"": {
    ""test"": {
      ""type"": ""object""
    }
  },
  ""items"": {
    ""$ref"": ""#/properties/test""
  }
}", json);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:26,代码来源:JSchemaWriterTests.cs

示例2: WriteTo_MaximumLength_Large

        public void WriteTo_MaximumLength_Large()
        {
            JSchema s = new JSchema
            {
                MaximumLength = long.MaxValue
            };

            string json = s.ToString();

            StringAssert.AreEqual(@"{
  ""maxLength"": 9223372036854775807
}", json);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaWriterTests.cs

示例3: WriteTo_UniqueItems

        public void WriteTo_UniqueItems()
        {
            JSchema s = new JSchema
            {
                UniqueItems = true
            };

            string json = s.ToString();

            StringAssert.AreEqual(@"{
  ""uniqueItems"": true
}", json);
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:13,代码来源:JSchemaWriterTests.cs

示例4: Example

        public void Example()
        {
            #region Usage
            JSchema schema = new JSchema
            {
                Type = JSchemaType.Object,
                Properties =
                {
                    { "name", new JSchema { Type = JSchemaType.String } },
                    {
                        "hobbies", new JSchema
                        {
                            Type = JSchemaType.Array,
                            Items = { new JSchema { Type = JSchemaType.String } }
                        }
                    },
                }
            };

            string schemaJson = schema.ToString();

            Console.WriteLine(schemaJson);
            // {
            //   "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

            Assert.IsTrue(valid);
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:50,代码来源:CreateJsonSchemaManually.cs

示例5: SerializeSchema

        public void SerializeSchema()
        {
            JSchema schema = new JSchema
            {
                Properties =
                {
                    { "first", new JSchema { Type = JSchemaType.String | JSchemaType.Null } }
                }
            };

            string s1 = schema.ToString();
            string s2 = JsonConvert.SerializeObject(schema, Formatting.Indented);

            Assert.AreEqual(s1, s2);
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:15,代码来源:SerializationTests.cs

示例6: WriteTo_ReferenceToPatternChild

        public void WriteTo_ReferenceToPatternChild()
        {
            JSchema nested = new JSchema
            {
                Type = JSchemaType.Object
            };

            JSchema s = new JSchema();
            s.Id = new Uri("http://www.jnk.com/");
            s.Properties["pattern_parent"] = new JSchema
            {
                PatternProperties =
                {
                    { "///~~~test~/~/~", nested }
                }
            };
            s.Properties["ref_parent"] = new JSchema
            {
                Items =
                {
                    nested
                }
            };

            string json = s.ToString();

            StringAssert.AreEqual(@"{
  ""id"": ""http://www.jnk.com/"",
  ""properties"": {
    ""pattern_parent"": {
      ""patternProperties"": {
        ""///~~~test~/~/~"": {
          ""type"": ""object""
        }
      }
    },
    ""ref_parent"": {
      ""items"": {
        ""$ref"": ""#/properties/pattern_parent/patternProperties/~1~1~1~0~0~0test~0~1~0~1~0""
      }
    }
  }
}", json);
        }
开发者ID:Nangal,项目名称:Newtonsoft.Json.Schema,代码行数:44,代码来源:JSchemaWriterTests.cs

示例7: 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

示例8: WriteComplex

        public void WriteComplex()
        {
            JSchema schema = new JSchema();
            schema.Id = new Uri("root", UriKind.RelativeOrAbsolute);
            schema.Type = JSchemaType.Boolean;

            JSchema file = new JSchema();
            file.Id = new Uri("file", UriKind.RelativeOrAbsolute);
            file.Properties.Add("blah", schema);
            file.ExtensionData["definitions"] = new JObject
            {
                { "parent", schema }
            };

            schema.Properties.Add("storage", file);
            schema.ExtensionData["definitions"] = new JObject
            {
                { "file", file },
                { "file2", file }
            };
            schema.Items.Add(new JSchema
                {
                    Type = JSchemaType.Integer | JSchemaType.Null
                });
            schema.Items.Add(file);
            schema.ItemsPositionValidation = true;
            schema.Not = file;
            schema.AllOf.Add(file);
            schema.AllOf.Add(new JSchema
            {
                Type = JSchemaType.Integer | JSchemaType.Null
            });
            schema.AllOf.Add(file);
            schema.AnyOf.Add(file);
            schema.AnyOf.Add(new JSchema
                {
                    Type = JSchemaType.Integer | JSchemaType.Null
                });
            schema.AnyOf.Add(schema);
            schema.OneOf.Add(file);
            schema.OneOf.Add(new JSchema
                {
                    Type = JSchemaType.Integer | JSchemaType.Null
                });
            schema.OneOf.Add(schema);
            schema.Not = file;

            JSchema file2 = (JSchema)schema.ExtensionData["definitions"]["file"];

            Assert.AreEqual(file, file2);

            string json = schema.ToString();

            StringAssert.AreEqual(@"{
  ""id"": ""root"",
  ""definitions"": {
    ""file"": {
      ""id"": ""file"",
      ""definitions"": {
        ""parent"": {
          ""$ref"": ""root""
        }
      },
      ""properties"": {
        ""blah"": {
          ""$ref"": ""root""
        }
      }
    },
    ""file2"": {
      ""$ref"": ""file""
    }
  },
  ""type"": ""boolean"",
  ""properties"": {
    ""storage"": {
      ""$ref"": ""file""
    }
  },
  ""items"": [
    {
      ""type"": [
        ""integer"",
        ""null""
      ]
    },
    {
      ""$ref"": ""file""
    }
  ],
  ""allOf"": [
    {
      ""$ref"": ""file""
    },
    {
      ""type"": [
        ""integer"",
        ""null""
      ]
    },
//.........这里部分代码省略.........
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:101,代码来源:JSchemaWriterTests.cs

示例9: ReferenceToNestedSchemaWithIdInResolvedSchema_Root

        public void ReferenceToNestedSchemaWithIdInResolvedSchema_Root()
        {
            JSchema nested = new JSchema();
            nested.Id = new Uri("nested.json", UriKind.RelativeOrAbsolute);
            nested.Type = JSchemaType.String;

            JSchema root = new JSchema
            {
                Id = new Uri("http://test.test"),
                Items = 
                {
                    nested
                }
            };

            string json = @"{""$ref"":""http://test.test/nested.json""}";

            NestedPreloadedResolver resolver = new NestedPreloadedResolver();
            resolver.Add(root.Id, root.ToString());

            JSchemaReader schemaReader = new JSchemaReader(resolver);
            JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));

            Assert.AreEqual(new Uri("nested.json", UriKind.RelativeOrAbsolute), schema.Id);

            Assert.AreEqual(JSchemaType.String, schema.Type);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:27,代码来源:JSchemaReaderTests.cs

示例10: ReferenceToNestedSchemaWithIdInResolvedSchema_ExtensionData

        public void ReferenceToNestedSchemaWithIdInResolvedSchema_ExtensionData()
        {
            JSchema nested = new JSchema();
            nested.Id = new Uri("nested.json", UriKind.RelativeOrAbsolute);

            JSchema root = new JSchema
            {
                Id = new Uri("http://test.test"),
                ExtensionData =
                {
                    { "nested", nested }
                }
            };
            string rootJson = root.ToString();

            string json = @"{
  ""type"":[""array""],
  ""items"":{""$ref"":""http://test.test/nested.json""}
}";

            NestedPreloadedResolver resolver = new NestedPreloadedResolver();
            resolver.Add(root.Id, rootJson);

            JSchemaReader schemaReader = new JSchemaReader(resolver);
            JSchema schema = schemaReader.ReadRoot(new JsonTextReader(new StringReader(json)));

            Assert.AreEqual(new Uri("nested.json", UriKind.RelativeOrAbsolute), schema.Items[0].Id);

            Assert.AreEqual(nested, schema.Items[0]);
        }
开发者ID:latticework,项目名称:Newtonsoft.Json.Schema,代码行数:30,代码来源:JSchemaReaderTests.cs

示例11: RootId_NestedId

        public void RootId_NestedId()
        {
            JSchema prop1 = new JSchema
            {
                Id = new Uri("test.json/", UriKind.RelativeOrAbsolute),
                Items =
                {
                    new JSchema(),
                    new JSchema
                    {
                        Id = new Uri("#fragmentItem2", UriKind.RelativeOrAbsolute),
                        Items =
                        {
                            new JSchema(),
                            new JSchema { Id = new Uri("#fragmentItem2Item2", UriKind.RelativeOrAbsolute) },
                            new JSchema { Id = new Uri("file.json", UriKind.RelativeOrAbsolute) },
                            new JSchema { Id = new Uri("/file1.json", UriKind.RelativeOrAbsolute) }
                        },
                        ItemsPositionValidation = true
                    }
                },
                ItemsPositionValidation = true
            };
            JSchema prop2 = new JSchema
            {
                Id = new Uri("#fragment", UriKind.RelativeOrAbsolute),
                Not = new JSchema()
            };
            JSchema root = new JSchema
            {
                Id = new Uri("http://localhost/", UriKind.RelativeOrAbsolute),
                Properties =
                {
                    { "prop1", prop1 },
                    { "prop2", prop2 }
                },
                ExtensionData =
                {
                    {
                        "definitions",
                        new JObject
                        {
                            { "def1", new JSchema() },
                            { "def2", new JSchema { Id = new Uri("def2.json", UriKind.RelativeOrAbsolute) } },
                            {
                                "defn",
                                new JArray
                                {
                                    new JValue(5),
                                    new JSchema()
                                }
                            }
                        }
                    }
                }
            };

            Console.WriteLine(root.ToString());

            JSchemaDiscovery discovery = new JSchemaDiscovery();
            discovery.Discover(root, null);

            int i = 0;

            foreach (KnownSchema knownSchema in discovery.KnownSchemas)
            {
                Console.WriteLine(knownSchema.Id);
            }

            Assert.AreEqual(new Uri("http://localhost/#", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root, discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/#/definitions/def1", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual((JSchema)root.ExtensionData["definitions"]["def1"], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/def2.json", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual((JSchema)root.ExtensionData["definitions"]["def2"], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/#/definitions/defn/1", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual((JSchema)root.ExtensionData["definitions"]["defn"][1], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/#/items/0", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"].Items[0], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/#fragmentItem2", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"].Items[1], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/#fragmentItem2/items/0", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"].Items[1].Items[0], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/#fragmentItem2Item2", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"].Items[1].Items[1], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/test.json/file.json", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
            Assert.AreEqual(root.Properties["prop1"].Items[1].Items[2], discovery.KnownSchemas[i++].Schema);

            Assert.AreEqual(new Uri("http://localhost/file1.json", UriKind.RelativeOrAbsolute), discovery.KnownSchemas[i].Id);
//.........这里部分代码省略.........
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:101,代码来源:JSchemaDiscoveryTests.cs


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