我们使用的是asp.net,很多时候我们发现,我们需要编写重复的代码来保存一些属性到会话或cookie或缓存:
例如:
public UserMaster CurrentUserMaster{
get{
return Session["CurrentUserMaster"] as UserMaster;
}
set {
Session["CurrentUserMaster"] = value;
}
}
public int ViewTimes{
get{
return (Int32)Cache["ViewTimes"];
}
set {
Cache["ViewTimes"] = value;
}
}
…
有没有这样写代码的方法?
[Session("Session-Key-CurrentUserMaster")]
public UserMaster CurrentUserMaster{get;set;}
[Cache("Cache-Key-ViewTimes")]
public int ViewTimes{get;set;}
然后自动保存这些属性到session, cache等
我找到了一篇文章之前,我想实现其他容器,谢谢:http://www.codeproject.com/Articles/54921/Automatic-ViewState-Properties-with-the-ViewState
我找到了这个问题的答案:http://www.cnblogs.com/cyq1162/archive/2012/05/30/2526573.html