2013-04-08 26 views
0

我想根据调试标志设置一个方法属性。我预计会有编译时间问题。也许有人可以想到一种解决方法,它的工作原理类似于它的工作原理。Asp.Net Mvc方法基于HttpContext.Current.IsDebuggingEnabled的OutputCache属性集

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

回答

0

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

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

..?

编辑:我已经证实这将适用于我的测试使用Serializable属性。应该为你想要实现的目标而工作(不确定它是否是最好的解决方案,但是它可行!)。