ISessionStateItemCollection Interfaccia

Definizione

Definisce il contratto per l'insieme utilizzato dallo stato sessione ASP.NET per la gestione della sessione.

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
Derivato
Implementazioni

Esempio

L'esempio di codice seguente implementa e ISessionStateItemCollection usa la SortedList classe per archiviare i nomi e i valori delle variabili di stato della sessione.

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

Commenti

L'interfaccia ISessionStateItemCollection definisce la raccolta di elementi di sessione esposti al codice dell'applicazione dalla HttpSessionStateContainer classe .

L'implementazione ASP.NET dell'interfaccia ISessionStateItemCollection è la SessionStateItemCollection classe .

Se si crea una classe derivata dalla SessionStateStoreProviderBase classe per archiviare i dati della sessione, è possibile usare la SessionStateItemCollection classe per gestire gli oggetti archiviati o implementare l'interfaccia ISessionStateItemCollection in una gestione raccolta personalizzata.

Se si implementa l'interfaccia, è necessario creare anche una classe che eredita la classe per usare l'implementazione ISessionStateItemCollection SessionStateStoreProviderBase per gestire le variabili di ISessionStateItemCollection sessione.

Un'implementazione ISessionStateItemCollection deve anche implementare i membri dell'interfaccia ICollection .

Proprietà

Count

Ottiene il numero di elementi contenuti in ICollection.

(Ereditato da ICollection)
Dirty

Ottiene o imposta un valore che indica se l'insieme è stato contrassegnato come modificato.

IsSynchronized

Ottiene un valore che indica se l'accesso a ICollection è sincronizzato (thread-safe).

(Ereditato da ICollection)
Item[Int32]

Ottiene o imposta un valore nell'insieme in base all'indice numerico.

Item[String]

Ottiene o imposta un valore nell'insieme in base al nome.

Keys

Ottiene un insieme dei nomi delle variabili per tutti i valori archiviati nell'insieme.

SyncRoot

Ottiene un oggetto che può essere usato per sincronizzare l'accesso a ICollection.

(Ereditato da ICollection)

Metodi

Clear()

Rimuove tutti i valori e le chiavi dall'insieme dello stato sessione.

CopyTo(Array, Int32)

Copia gli elementi di ICollection in Array a partire da un particolare indice Array.

(Ereditato da ICollection)
GetEnumerator()

Restituisce un enumeratore che consente di eseguire l'iterazione di una raccolta.

(Ereditato da IEnumerable)
Remove(String)

Elimina un elemento dall'insieme.

RemoveAt(Int32)

Elimina dall'insieme un elemento con un indice specifico.

Metodi di estensione

Cast<TResult>(IEnumerable)

Esegue il cast degli elementi di un oggetto IEnumerable nel tipo specificato.

OfType<TResult>(IEnumerable)

Filtra gli elementi di un oggetto IEnumerable in base a un tipo specificato.

AsParallel(IEnumerable)

Consente la parallelizzazione di una query.

AsQueryable(IEnumerable)

Converte un oggetto IEnumerable in un oggetto IQueryable.

Si applica a

Vedi anche