由于很多属性都是由避免未封闭的属性设计的,我正在寻找一种解决方案来设置属性值(我的第一个想法是继承类并设置一个构造函数以检查web-config - 但无法使用封闭类):
命名空间System.Web.Http.Description
中有ApiExplorerSettingsAttribute
我希望以下API操作在web-config中的值为false时隐藏:
<Api.Properties.Settings>
<setting name="Hoster">
<value>False</value>
</setting>
</Api.Properties.Settings>
这个操作会像这样:
[HttpGet, Route("api/bdlg")]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(BdlgDataStorage))]
[ApiExplorerSettings(IgnoreApi = Properties.Settings.Default.Hoster)]
private async Task<BdlgDataStorage> GetBdlgStorageValues()
{
using (var context = new BdlgContext())
return context.BdlgDataStorages
.Include(s=>s.ChangeTrack)
.Where(w=>w.Isle > 56)
.Select(selectorFunction)
.ToListAsync();
}
重要的一行是:
[ApiExplorerSettings(IgnoreApi = Properties.Settings.Default.Hoster)]
这里,我遇到了编译错误:引用参数必须是常量表达式、typeof表达式或属性参数类型的数组创建表达式。
有人知道如何将IgnoreApi的值设置为与web-config相同吗?