/// 自动保存属性. 在页面类的属性上面加上该属性. 可以使得该字段或属性能够自动保存和自动加载.////// 自动保存属性. 能够实现字段或属性值的自动保存和加载. 该属性只在非静态字段或属性上才能生效.//////
/// 但是该属性必须是可序列化的. 否则抛出异常. 该属性只在非公有字段或属性上才能生效.
///[attributeusage(attributetargets.property | attributetargets.field, allowmultiple = false, inherited = false)]public class autosaveattribute : attribute{////// 初始化创建一个类的实例. 使得具有该属性的类的属性具有自动保存的特性. ///public autosaveattribute() { }}
////// 用户控件类型及自动保存属性成员缓冲字典///protected static dictionarycachedic = null; ////// 获得成员列表的绑定标识.///protected static bindingflags flag;////// 初始化类. ///static basepage(){cachedic = new dictionary(); flag = bindingflags.public | bindingflags.nonpublic | bindingflags.instance | bindingflags.getfield | bindingflags.getproperty | bindingflags.flattenhierarchy;}////// 当前页面的类型///protected type currtype = null;////// 初始化当前页面的缓冲字典///protected void initcachedic(){// 获得当前实例类型currtype = page.gettype();memberinfo[] mems = null;if (!cachedic.trygetvalue(currtype, out mems)){// 自动保存属性处理var list = currtype.getmembers(flag).where(p => attribute.isdefined(p, typeof(autosave), false)).toarray();cachedic[currtype] = list;}}
////// 引发事件以对页进行初始化。 ////// 包含事件数据的。 protected override void oninit(eventargs e){if (page.ispostback){// 初始化当前用户控件的缓冲字典initcachedic();// 获得缓冲数据列表var list = getcachedata();// 自动加载 autosave 属性保存的值int index = 0;foreach (memberinfo info in cachedic[currtype]){if (info.membertype == membertypes.property){propertyinfo pi = info as propertyinfo;object value = list[index];if (value != null)pi.setvalue(this, value, null);}else if (info.membertype == membertypes.field){fieldinfo fi = info as fieldinfo;object value = list[index];fi.setvalue(this, value);}index++;}}}
////// 在这里实现属性的自动保存。///protected override object saveviewstate(){// 初始化当前用户控件的缓冲字典initcachedic();// 初始化要保存的属性值列表arraylist list = new arraylist();int index = 0;foreach (memberinfo info in cachedic[currtype]){if (info.membertype == membertypes.property){propertyinfo pi = info as propertyinfo;list[index] = pi.getvalue(this, null);}else if (info.membertype == membertypes.field){fieldinfo fi = info as fieldinfo;list[index] = fi.getvalue(this);}}// 保存更改savecachedata(list);return base.saveviewstate();}
private arraylist getcachedata(){return (arraylist)session[currtype];}private void savecachedata(arraylist data){session[currtype] = data;}
《黎明杀机》开发商正开发新的《Serious Sam》游戏 由Devolver发行
超英派遣中心即将登陆Xbox Play Anywhere 深入了解这款独特而备受喜爱的冒险游戏
在《Hunter: The Reckoning – Deathwish》中怎么从猎物蜕变为猎手
《The Expanse: Osiris Reborn》——深入了解玩法 新同伴 封闭测试及发行窗口
Alien Deathstorm 科幻生存与动作结合 打造全新第一人称恐怖混合体验
宝可梦公司已在考虑未来可用口袋妖怪总数达到“或许一万只”
幸存者村庄2
怪可爱的店折相思菜单
怪可爱的店折相思菜单是一款画风治愈的模拟经营佳作,内置折相思菜单解锁多项便利功能
lol电竞经理人手游
lol电竞经理人手游让你可以成为职业的电竞经理人,在游戏中掌控游戏的走向!豪华阵
梦幻奶茶屋小游戏
梦幻奶茶屋是一款主打温馨治愈氛围的休闲经营作品,玩家将化身元气满满的奶茶店店长,
萌宠养成物语无限金币版
萌宠养成物语无限金币版是一款治愈系模拟养成游戏,以可爱卡通画风构建温馨虚拟世界,