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


C# JsonSchema.WriteTo方法代码示例

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


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

示例1: Example

        public void Example()
        {
            #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 directly to a file
            using (StreamWriter file = File.CreateText(@"c:\schema.json"))
            using (JsonTextWriter writer = new JsonTextWriter(file))
            {
                schema.WriteTo(writer);
            }
            #endregion
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:19,代码来源:SaveJsonSchemaToFile.cs

示例2: WriteTo_PatternProperties

    public void WriteTo_PatternProperties()
    {
      JsonSchema schema = new JsonSchema();
      schema.PatternProperties = new Dictionary<string, JsonSchema>
        {
          { "[abc]", new JsonSchema() }
        };

      StringWriter writer = new StringWriter();
      JsonTextWriter jsonWriter = new JsonTextWriter(writer);
      jsonWriter.Formatting = Formatting.Indented;

      schema.WriteTo(jsonWriter);

      string json = writer.ToString();

      Assert.AreEqual(@"{
  ""patternProperties"": {
    ""[abc]"": {}
  }
}", json);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:22,代码来源:JsonSchemaTests.cs

示例3: WriteTo_ExclusiveMinimum_ExclusiveMaximum

    public void WriteTo_ExclusiveMinimum_ExclusiveMaximum()
    {
      JsonSchema schema = new JsonSchema();
      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();

      Assert.AreEqual(@"{
  ""exclusiveMinimum"": true,
  ""exclusiveMaximum"": true
}", json);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:19,代码来源:JsonSchemaTests.cs

示例4: HandleContractMetadataAsync

        public virtual async Task<bool> HandleContractMetadataAsync(ServerActionContext context)
        {
            try
            {
                string result = string.Empty;
                string actionName = context.HttpContext.Request.Query["action"]?.Trim();
                MethodInfo action = null;

                if (!string.IsNullOrEmpty(actionName))
                {
                    action = _actionResolver.Resolve(context.Contract, actionName);
                }

                if (action == null)
                {
                    var contractMetadata = CrateContractMetadata(context);
                    result = JsonConvert.SerializeObject(
                        contractMetadata,
                        Formatting.Indented,
                        new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                }
                else
                {
                    context.Action = action;
                    JsonSchema actionSchema = new JsonSchema
                                                  {
                                                      Properties = new Dictionary<string, JsonSchema>(),
                                                      Description = $"Request and response parameters for action '{actionName}'."
                                                  };

                    List<ParameterInfo> actionParameters = BoltFramework.GetSerializableParameters(action).ToList();
                    if (actionParameters.Any())
                    {
                        JsonSchemaGenerator generator = new JsonSchemaGenerator();
                        JsonSchema arguments = new JsonSchema
                                                   {
                                                       Properties =
                                                           actionParameters.ToDictionary(
                                                               p => p.Name,
                                                               p => generator.Generate(p.ParameterType)),
                                                       Required = true,
                                                       Type = JsonSchemaType.Object,
                                                   };

                        actionSchema.Properties.Add("request", arguments);
                    }

                    if (context.ResponseType != typeof(void))
                    {
                        JsonSchemaGenerator generator = new JsonSchemaGenerator();
                        actionSchema.Properties.Add("response", generator.Generate(context.ResponseType));
                    }

                    using (var sw = new StringWriter())
                    {
                        using (JsonTextWriter jw = new JsonTextWriter(sw))
                        {

                            jw.Formatting = Formatting.Indented;
                            actionSchema.WriteTo(jw);
                        }
                        result = sw.GetStringBuilder().ToString();
                    }
                }

                context.HttpContext.Response.ContentType = "application/json";
                context.HttpContext.Response.StatusCode = 200;
                await context.HttpContext.Response.WriteAsync(result);
                return true;
            }
            catch (Exception e)
            {
                Logger.LogWarning(
                    BoltLogId.HandleContractMetadataError,
                    "Failed to generate Bolt metadata for contract '{0}'. Error: {1}",
                    context.Contract.Name,
                    e);
                return false;
            }
        }
开发者ID:geffzhang,项目名称:Bolt,代码行数:80,代码来源:BoltMetadataHandler.cs

示例5: WriteTo_PositionalItemsValidation_FalseWithItemsSchema

        public void WriteTo_PositionalItemsValidation_FalseWithItemsSchema()
        {
            JsonSchema schema = new JsonSchema();
            schema.Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.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:b-bot-110,项目名称:Newtonsoft.Json,代码行数:19,代码来源:JsonSchemaTests.cs

示例6: WriteTo_PositionalItemsValidation_True

        public void WriteTo_PositionalItemsValidation_True()
        {
            JsonSchema schema = new JsonSchema();
            schema.PositionalItemsValidation = 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:b-bot-110,项目名称:Newtonsoft.Json,代码行数:17,代码来源:JsonSchemaTests.cs


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