/// 自动保存属性. 在页面类的属性上面加上该属性. 可以使得该字段或属性能够自动保存和自动加载.////// 自动保存属性. 能够实现字段或属性值的自动保存和加载. 该属性只在非静态字段或属性上才能生效.//////
/// 但是该属性必须是可序列化的. 否则抛出异常. 该属性只在非公有字段或属性上才能生效.
///[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;}
罚罪1+2全80集阿里云盘全集资源链接-罚罪1+2全集高清1080P/4K阿里云盘资源下载无删减
邵氏精品禁品未删减资源在线看-必看的50部邵氏电影无删减观看入口
羞羞漫画高清最新资源-正规平台免费入口与无删减资源导航
日漫入口-官方认证安全入口与无删减日漫资源直达导航
一拳超人漫画入口-2026最新免费高清全集在线看
杨紫《生命树》1080p全40集迅雷磁力链接分享-杨紫《生命树》40集高清完整版迅雷云盘下载1080P(4k)资源