【发布时间】:2017-06-12 13:42:31
【问题描述】:
由于很多属性是由 avoid unsealed attributes 设计的,我正在寻找设置属性值的解决方案(我的第一个想法是继承类并设置一个构造函数来检查网络-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 中的值相同?
【问题讨论】:
标签: c# attributes