ISessionStateItemCollection Interface
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define o contrato para a coleção utilizada pelo estado da sessão ASP.NET para gerir a sessão.
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
- Derivado
- Implementações
Exemplos
O exemplo de código seguinte implementa a ISessionStateItemCollection e usa a SortedList classe para armazenar nomes e valores de variáveis de estado da sessão.
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
Observações
A ISessionStateItemCollection interface define a coleção de itens de sessão expostos ao código da aplicação pela HttpSessionStateContainer classe.
A ASP.NET implementação da interface ISessionStateItemCollection é a classe SessionStateItemCollection.
Se criar uma classe derivada da SessionStateStoreProviderBase classe para armazenar dados da sessão, pode usar a SessionStateItemCollection classe para gerir os objetos armazenados ou implementar a ISessionStateItemCollection interface no seu próprio gestor de coleções.
Se implementares a ISessionStateItemCollection interface, também deves criar uma classe que herde a SessionStateStoreProviderBase classe para aproveitar a tua ISessionStateItemCollection implementação e gerir variáveis de sessão.
Uma ISessionStateItemCollection implementação deve também implementar os membros da ICollection interface.
Propriedades
| Name | Description |
|---|---|
| Count |
Obtém o número de elementos contidos no ICollection. (Herdado de ICollection) |
| Dirty |
Recebe ou define um valor que indica se a coleção foi marcada como alterada. |
| IsSynchronized |
Recebe um valor que indica se o acesso ao ICollection é sincronizado (thread safe). (Herdado de ICollection) |
| Item[Int32] |
Obtém ou define um valor na coleção por índice numérico. |
| Item[String] |
Recebe ou define um valor na coleção pelo nome. |
| Keys |
Obtém uma coleção dos nomes das variáveis de todos os valores armazenados na coleção. |
| SyncRoot |
Obtém um objeto que pode ser usado para sincronizar o acesso ao ICollection. (Herdado de ICollection) |
Métodos
| Name | Description |
|---|---|
| Clear() |
Remove todos os valores e chaves da coleção de estados de sessão. |
| CopyTo(Array, Int32) |
Copia os elementos do ICollection para um Array, começando num índice particular Array . (Herdado de ICollection) |
| GetEnumerator() |
Devolve um enumerador que itera numa coleção. (Herdado de IEnumerable) |
| Remove(String) |
Apaga um item da coleção. |
| RemoveAt(Int32) |
Apaga um item num índice especificado da coleção. |
Métodos da Extensão
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
Permite a paralelização de uma consulta. |
| AsQueryable(IEnumerable) |
Converte um IEnumerable para um IQueryable. |
| Cast<TResult>(IEnumerable) |
Conjura os elementos de an IEnumerable para o tipo especificado. |
| OfType<TResult>(IEnumerable) |
Filtra os elementos de um IEnumerable com base num tipo especificado. |