ASP.Net WebApi 2示例文本属性

时间:2015-04-17 15:35:44

标签: c# asp.net asp.net-web-api asp.net-web-api2 asp.net-web-api-helppages

有没有办法使用属性为web api帮助页面生成提供样本?我知道我可以通过转到/ Areas / HelpPage / ...来提供样品 但是我想用他们的代码将它们全部放在一个地方。

这些方面的东西:

    /// <summary>
    /// userPrincipalName attribute of the user in AD
    /// </summary>
    [TextSample("john.smith@contoso.com")]
    public string UserPrincipalName;

1 个答案:

答案 0 :(得分:3)

这可以通过自己创建自定义属性来实现,例如:

[AttributeUsage(AttributeTargets.Property)]
public class TextSampleAttribute : Attribute
{
    public string Value { get; set; }

    public TextSampleAttribute(string value)
    {
        Value = value;
    }
}

然后像这样修改SetPublicProperties的{​​{1}}方法:

ObjectGenerator

我添加了一个检查以查看TextSampleAttribute是否已定义,如果是,则使用它的值而不是自动生成的值。