2013-04-08 30 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屬性。應該爲你想要實現的目標而工作(不確定它是否是最好的解決方案,但是它可行!)。