/// 自动保存属性. 在页面类的属性上面加上该属性. 可以使得该字段或属性能够自动保存和自动加载.////// 自动保存属性. 能够实现字段或属性值的自动保存和加载. 该属性只在非静态字段或属性上才能生效.//////
/// 但是该属性必须是可序列化的. 否则抛出异常. 该属性只在非公有字段或属性上才能生效.
///[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;}
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级