SiteMapNodeCollection.ReadOnly(SiteMapNodeCollection) Método

Definição

Retorna uma coleção somente leitura que contém os nós na coleção SiteMapNodeCollection especificada.

public:
 static System::Web::SiteMapNodeCollection ^ ReadOnly(System::Web::SiteMapNodeCollection ^ collection);
public static System.Web.SiteMapNodeCollection ReadOnly (System.Web.SiteMapNodeCollection collection);
static member ReadOnly : System.Web.SiteMapNodeCollection -> System.Web.SiteMapNodeCollection
Public Shared Function ReadOnly (collection As SiteMapNodeCollection) As SiteMapNodeCollection

Parâmetros

collection
SiteMapNodeCollection

O SiteMapNodeCollection que contém os objetos SiteMapNode a serem adicionados ao SiteMapNodeCollection somente leitura.

Retornos

SiteMapNodeCollection

Um SiteMapNodeCollection somente leitura com os mesmos elementos e a estrutura do SiteMapNode que o SiteMapNodeCollection original.

Exceções

collection é null.

Exemplos

O exemplo de código a seguir demonstra como usar a IsReadOnly propriedade para testar se uma SiteMapNodeCollection coleção é somente leitura ou modificável. Se siteNodes for modificável, MoveNode será chamado nele; caso contrário, um clone SiteMapNodeCollection será criado, usando siteNodes como base.

SiteMapNodeCollection siteNodes = SiteMap.RootNode.GetAllNodes();

if ( siteNodes.IsReadOnly ||
     siteNodes.IsFixedSize )
{
    Response.Write("Collection is read-only or has fixed size.<BR>");

    // Create a new, modifiable collection from the existing one.
    SiteMapNodeCollection modifiableCollection =
         new SiteMapNodeCollection(siteNodes);

    // The MoveNode example method moves a node from position one to
    // the last position in the collection.
    MoveNode(modifiableCollection);
}
else {
    MoveNode(siteNodes);
}

Dim siteNodes As SiteMapNodeCollection
siteNodes = SiteMap.RootNode.GetAllNodes()

If siteNodes.IsReadOnly Or siteNodes.IsFixedSize Then

    Response.Write("Collection is read-only or has fixed size.<BR>")

    ' Create a new, modifiable collection from the existing one.
    Dim modifiableCollection As SiteMapNodeCollection
    modifiableCollection = New SiteMapNodeCollection(siteNodes)

    ' The MoveNode example method moves a node from position one to
    ' the last position in the collection.
    MoveNode(modifiableCollection)
Else
    MoveNode(siteNodes)
End If

Comentários

Você pode testar se uma SiteMapNodeCollection coleção é somente leitura verificando a IsReadOnly propriedade. A IsFixedSize propriedade também retorna true quando um SiteMapNodeCollection é somente leitura.

Notas aos Herdeiros

Uma coleção somente SiteMapNodeCollection leitura dá suporte a operações de leitura e pesquisa, mas não dá suporte aos Add(SiteMapNode)métodos, AddRangee Clear()Remove(SiteMapNode)Insert(Int32, SiteMapNode)métodos, RemoveAt(Int32) nem ao setter na propriedade Item[Int32]do indexador padrão.

Aplica-se a