4

是否可以向属性添加描述属性?

我正在使用 json.net 生成架构:

var shema = new Newtonsoft.Json.Schema.JsonSchemaGenerator();
var sh = shema.Generate(typeof(APIDocumentation.AlertDTO), false).ToString();

我想为用户添加一些简单的文档以了解每个字段的含义。现在我可以使用 [JsonObject(Description = "my description")] 向类添加描述属性,但它不能与类内的属性一起使用。有没有可能做类似的事情:

[JsonObject(Description = "My description")]
public class AlertDTO
{
    [SomeAttribute(Description="Property description")]
    public string Type { get; set; }

}

或者也许有一种方法可以获取 VS 风格的注释并将它们添加到 JSON 模式中作为描述?

4

1 回答 1

2

您可以使用 System.ComponentModel 命名空间中的 Description 属性。

我花了一段时间才找到,但文档中有一个示例:https ://www.newtonsoft.com/jsonschema/help/html/GenerateWithDescriptions.htm

于 2017-10-18T03:55:35.070 回答