ISessionStateItemCollection 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义 ASP.NET 会话状态用于管理会话的集合的协定。
public interface class ISessionStateItemCollection : System::Collections::ICollection
public interface ISessionStateItemCollection : System.Collections.ICollection
type ISessionStateItemCollection = interface
interface ICollection
interface IEnumerable
Public Interface ISessionStateItemCollection
Implements ICollection
- 派生
- 实现
示例
下面的代码示例实现 ISessionStateItemCollection 并使用 SortedList 类来存储会话状态变量名称和值。
using System;
using System.Web;
using System.Web.SessionState;
using System.Collections;
using System.Collections.Specialized;
namespace Samples.AspNet.Session
{
public class MySessionStateItemCollection : ISessionStateItemCollection
{
private SortedList pItems = new SortedList();
private bool pDirty = false;
public bool Dirty
{
get { return pDirty; }
set { pDirty = value; }
}
public object this[int index]
{
get { return pItems[index]; }
set
{
pItems[index] = value;
pDirty = true;
}
}
public object this[string name]
{
get { return pItems[name]; }
set
{
pItems[name] = value;
pDirty = true;
}
}
public NameObjectCollectionBase.KeysCollection Keys
{
get { return (NameObjectCollectionBase.KeysCollection)pItems.Keys; }
}
public int Count
{
get { return pItems.Count; }
}
public Object SyncRoot
{
get { return this; }
}
public bool IsSynchronized
{
get { return false; }
}
public IEnumerator GetEnumerator()
{
return pItems.GetEnumerator();
}
public void Clear()
{
pItems.Clear();
pDirty = true;
}
public void Remove(string name)
{
pItems.Remove(name);
pDirty = true;
}
public void RemoveAt(int index)
{
if (index < 0 || index >= this.Count)
throw new ArgumentOutOfRangeException("The specified index is not within the acceptable range.");
pItems.RemoveAt(index);
pDirty = true;
}
public void CopyTo(Array array, int index)
{
pItems.CopyTo(array, index);
}
}
}
Imports System.Web
Imports System.Web.SessionState
Imports System.Collections
Imports System.Collections.Specialized
Namespace Samples.AspNet.Session
Public Class MySessionStateItemCollection
Implements ISessionStateItemCollection
Private pItems As SortedList = New SortedList()
Private pDirty As Boolean = False
Public Property Dirty As Boolean Implements ISessionStateItemCollection.Dirty
Get
Return pDirty
End Get
Set
pDirty = value
End Set
End Property
Public Property Item(index As Integer) As Object Implements ISessionStateItemCollection.Item
Get
Return pItems(index)
End Get
Set
pItems(index) = value
pDirty = True
End Set
End Property
Public Property Item(name As String) As Object Implements ISessionStateItemCollection.Item
Get
Return pItems(name)
End Get
Set
pItems(name) = value
pDirty = True
End Set
End Property
Public ReadOnly Property Keys As NameObjectCollectionBase.KeysCollection _
Implements ISessionStateItemCollection.Keys
Get
Return CType(pItems.Keys, NameObjectCollectionBase.KeysCollection)
End Get
End Property
Public ReadOnly Property Count As Integer Implements ICollection.Count
Get
Return pItems.Count
End Get
End Property
Public ReadOnly Property SyncRoot As Object Implements ICollection.SyncRoot
Get
Return Me
End Get
End Property
Public ReadOnly Property IsSynchronized As Boolean Implements ICollection.IsSynchronized
Get
Return False
End Get
End Property
Public Function GetEnumerator() As IEnumerator Implements ICollection.GetEnumerator
Return pItems.GetEnumerator()
End Function
Public Sub Clear() Implements ISessionStateItemCollection.Clear
pItems.Clear()
pDirty = True
End Sub
Public Sub Remove(name As String) Implements ISessionStateItemCollection.Remove
pItems.Remove(name)
pDirty = True
End Sub
Public Sub RemoveAt(index As Integer) Implements ISessionStateItemCollection.RemoveAt
If index < 0 OrElse index >= Me.Count Then _
Throw New ArgumentOutOfRangeException("The specified index is not within the acceptable range.")
pItems.RemoveAt(index)
pDirty = True
End Sub
Public Sub CopyTo(array As Array, index As Integer) Implements ICollection.CopyTo
pItems.CopyTo(array, index)
End Sub
End Class
End Namespace
注解
该 ISessionStateItemCollection 接口定义类向 HttpSessionStateContainer 应用程序代码公开的会话项的集合。
ISessionStateItemCollection 接口的 ASP.NET 实现是 SessionStateItemCollection 类。
如果创建派生自 SessionStateStoreProviderBase 该类的类来存储会话数据,则可以使用该 SessionStateItemCollection 类来管理存储的对象,或在自己的集合管理器上实现 ISessionStateItemCollection 接口。
如果实现 ISessionStateItemCollection 接口,还必须创建一个继承该类的 SessionStateStoreProviderBase 类,以便利用 ISessionStateItemCollection 实现来管理会话变量。
ISessionStateItemCollection实现还必须实现接口的成员ICollection。
属性
| 名称 | 说明 |
|---|---|
| Count |
获取包含在 . 中的 ICollection元素数。 (继承自 ICollection) |
| Dirty |
获取或设置一个值,该值指示集合是否已标记为已更改。 |
| IsSynchronized |
获取一个值,该值指示对 ICollection 同步的访问是否同步(线程安全)。 (继承自 ICollection) |
| Item[Int32] |
按数值索引获取或设置集合中的值。 |
| Item[String] |
按名称获取或设置集合中的值。 |
| Keys |
获取集合中存储的所有值的变量名称的集合。 |
| SyncRoot |
获取可用于同步对 . ICollection的访问的对象。 (继承自 ICollection) |
方法
| 名称 | 说明 |
|---|---|
| Clear() |
从会话状态集合中删除所有值和键。 |
| CopyTo(Array, Int32) |
将元素ICollection复制到从特定Array索引开始的元素Array。 (继承自 ICollection) |
| GetEnumerator() |
返回循环访问集合的枚举器。 (继承自 IEnumerable) |
| Remove(String) |
从集合中删除项。 |
| RemoveAt(Int32) |
从集合中删除位于指定索引处的项。 |
扩展方法
| 名称 | 说明 |
|---|---|
| AsParallel(IEnumerable) |
启用查询的并行化。 |
| AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |
| Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定类型。 |
| OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |