0

我正在尝试根据调试标志设置方法属性。我预计会有编译时间问题。也许有人可以想到一种解决方法,它类似于如果它有效的话。

[OutputCache(
    NoStore = HttpContext.Current.IsDebuggingEnabled, 
    Duration=(HttpContext.Current.IsDebuggingEnabled)?0:15
)]///TODO: REMOVE THIS Attribute AFTER TESTING!
public ActionResult RenderSomething(int somethingID)
{
...
}
4

1 回答 1

0

你不能使用预处理条件吗?

#if DEBUG
    [OutputCache(
        NoStore = HttpContext.Current.IsDebuggingEnabled, 
        Duration = 0)]
#else
    [OutputCache(
        NoStore = HttpContext.Current.IsDebuggingEnabled, 
        Duration = 15)]    
#endif

..?

编辑:我已经确认这将适用于我使用该Serializable属性的测试。应该为你想要达到的目标工作(虽然不确定它是否是最好的解决方案..但它有效!)。

于 2013-04-08T23:35:11.087 回答