asp.net – 如何创建Generic StateManagedCollection?
发布时间:2020-05-24 10:58:50 所属栏目:asp.Net 来源:互联网
导读:一个例子描述为 here.但是作者显然忘记包含下载代码. 另一个例子显示为here.但是,这个例子并不完全(如评论中所述). 你是怎么做到这一点的? DanHerbert得到了它. Darn,我也花了几个小时!在尝试回答这个问题的过程中,我提出了一个简化的通用StateManagedColle
|
一个例子描述为 here.但是作者显然忘记包含下载代码. 另一个例子显示为here.但是,这个例子并不完全(如评论中所述). 你是怎么做到这一点的? 解决方法DanHerbert得到了它. Darn,我也花了几个小时!在尝试回答这个问题的过程中,我提出了一个简化的通用StateManagedCollection,它继承自框架的内置StateManagedCollection,基于版本 here.也许你会发现它很有用.我的示例项目的完整源代码可用于 here.using System;
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Web;
using System.Collections.Generic;
using System.Web.UI;
namespace Web
{
public abstract class StateManagedCollection<T> : StateManagedCollection,IList<T>,ICollection<T>,IEnumerable<T>
where T : class,IStateManagedItem,new()
{
protected override object CreateKnownType(int index)
{
return Activator.CreateInstance<T>();
}
protected override Type[] GetKnownTypes()
{
return new Type[] { typeof(T) };
}
protected override void SetDirtyObject(object o)
{
((IStateManagedItem)o).SetDirty();
}
#region IList<T> Members
public int IndexOf(T item)
{
return ((IList)this).IndexOf(item);
}
public void Insert(int index,T item)
{
((IList)this).Insert(index,item);
if (((IStateManager)this).IsTrackingViewState)
{
this.SetDirty();
}
}
public void RemoveAt(int index)
{
((IList)this).RemoveAt(index);
if (((IStateManager)this).IsTrackingViewState)
{
this.SetDirty();
}
}
public T this[int index]
{
get { return (T)this[index]; }
set { this[index] = value; }
}
#endregion
#region ICollection<T> Members
public void Add(T item)
{
((IList)this).Add(item);
this.SetDirty();
}
public bool Contains(T item)
{
return ((IList)this).Contains(item);
}
public void CopyTo(T[] array,int arrayIndex)
{
((IList)this).CopyTo(array,arrayIndex);
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove(T item)
{
if (((IList)this).Contains(item))
{
((IList)this).Remove(item);
return true;
}
return false;
}
#endregion
#region IEnumerable<T> Members
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
throw new NotImplementedException();
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return ((IList)this).GetEnumerator();
}
#endregion
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何在ASP.NET MVC中使用querystring路由UR
- Asp.net配合easyui实现返回json数据实例
- asp.net-web-api – 在ASP.NET Web API控制器的nunit测试中
- asp.net-mvc-2 – 使用Ninject返回null的HttpHandler属性注
- 为什么Asp.Net MVC 5在_Layout.cshtml的底部放置@ Scripts.
- asp.net-mvc-3 – ASP.Net MVC 3 – 编辑器模板的客户端不显
- ASP.NET Core 2.0 Web API响应缓存
- asp.net – 如何添加一个模板到一个UserControl?
- asp.net-mvc – 如何单元测试HtmlHelper与Moq?
- asp.net-mvc – UpdateModel前缀 – ASP.NET MVC
推荐文章
站长推荐
- asp.net-mvc – 可以在ASP.NET MVC中停止表单的多
- asp.net – HttpServerUtility.UrlPathEncode vs
- asp.net-mvc – 避免“类或CssClass值未定义”AS
- ASP.NET页面生命周期解释
- asp.net – 在测试期间如何使电子邮件到本地文件
- asp.net-mvc – 在ASP.NET MVC中的View和Partial
- 防止ASP.Net中的重复回发(C#)
- asp.net – 如何在EF DbContext和AspNet Members
- asp.net – 我可以在Visual Studio 2008中使用MV
- 是*不*使用asp.net成员资格提供程序一个坏主意?
热点阅读
