ISessionStateItemCollection ISessionStateItemCollection ISessionStateItemCollection ISessionStateItemCollection Interface

定义

为 ASP.NET 会话状态使用的集合定义协定,以管理会话。Defines the contract for the collection used by ASP.NET session state to manage session.

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
派生
实现

示例

下面的代码示例实现ISessionStateItemCollectionSortedList使用类存储会话状态变量名称和值。The following code example implements the ISessionStateItemCollection and uses the SortedList class to store session-state variable names and values.

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按类向应用程序代码公开的会话项的集合。The ISessionStateItemCollection interface defines the collection of session items exposed to application code by the HttpSessionStateContainer class.

ISessionStateItemCollection接口的 ASP.NET 实现SessionStateItemCollection是类。The ASP.NET implementation of the ISessionStateItemCollection interface is the SessionStateItemCollection class.

如果创建从SessionStateStoreProviderBase类派生的类以存储会话数据, 则可以SessionStateItemCollection使用类来管理存储的对象, 或在自己的集合管理ISessionStateItemCollection器中实现该接口。If you create a class derived from the SessionStateStoreProviderBase class to store session data, you can either use the SessionStateItemCollection class to manage the stored objects or implement the ISessionStateItemCollection interface on your own collection manager.

如果实现ISessionStateItemCollection接口, 则还必须创建一个SessionStateStoreProviderBase继承类的类, 才能利用ISessionStateItemCollection实现来管理会话变量。If you implement the ISessionStateItemCollection interface, you must also create a class that inherits the SessionStateStoreProviderBase class in order to make use of your ISessionStateItemCollection implementation to manage session variables.

实现还必须实现ICollection接口的成员。 ISessionStateItemCollectionAn ISessionStateItemCollection implementation must also implement the members of the ICollection interface.

属性

Count Count Count Count

获取 ICollection 中包含的元素数。Gets the number of elements contained in the ICollection.

(Inherited from ICollection)
Dirty Dirty Dirty Dirty

获取或设置一个值,该值指示是否已将集合标记为“已更改”。Gets or sets a value indicating whether the collection has been marked as changed.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

获取一个值,该值指示是否同步对 ICollection 的访问(线程安全)。Gets a value indicating whether access to the ICollection is synchronized (thread safe).

(Inherited from ICollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

按照数字索引获取或设置集合中的值。Gets or sets a value in the collection by numerical index.

Item[String] Item[String] Item[String] Item[String]

按名称获取或设置集合中的值。Gets or sets a value in the collection by name.

Keys Keys Keys Keys

为存储在集合中的所有值获取变量名的集合。Gets a collection of the variable names for all values stored in the collection.

SyncRoot SyncRoot SyncRoot SyncRoot

获取可用于同步对 ICollection 的访问的对象。Gets an object that can be used to synchronize access to the ICollection.

(Inherited from ICollection)

方法

Clear() Clear() Clear() Clear()

从会话状态集合中移除所有的值和键。Removes all values and keys from the session-state collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

从特定的 ICollection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection to an Array, starting at a particular Array index.

(Inherited from ICollection)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)
Remove(String) Remove(String) Remove(String) Remove(String)

从集合中删除某个项。Deletes an item from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

删除集合中指定索引处的项。Deletes an item at a specified index from the collection.

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅