SiteMapNodeCollection.ReadOnly(SiteMapNodeCollection) Metod

Definition

Returnerar en skrivskyddad samling som innehåller noderna i den angivna SiteMapNodeCollection samlingen.

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

Parametrar

collection
SiteMapNodeCollection

Som SiteMapNodeCollection innehåller de SiteMapNode objekt som ska läggas till i den skrivskyddade SiteMapNodeCollection.

Returer

En skrivskyddad SiteMapNodeCollection med samma SiteMapNode element och struktur som den ursprungliga SiteMapNodeCollection.

Undantag

collection är null.

Exempel

Följande kodexempel visar hur du använder IsReadOnly egenskapen för att testa om en SiteMapNodeCollection samling är skrivskyddad eller kan ändras. Om siteNodes är ändringsbar MoveNode anropas den. Annars skapas en klon SiteMapNodeCollection med hjälp av siteNodes som bas.

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

Kommentarer

Du kan testa om en SiteMapNodeCollection samling är skrivskyddad genom att kontrollera egenskapen IsReadOnly . Egenskapen IsFixedSize returnerar true också när en SiteMapNodeCollection är skrivskyddad.

Anteckningar till arvingar

En skrivskyddad SiteMapNodeCollection samling stöder läs- och sökåtgärder, men stöder Add(SiteMapNode)inte metoderna , , AddRangeClear(), Insert(Int32, SiteMapNode), Remove(SiteMapNode)och RemoveAt(Int32) eller setter för standardegenskapen indexerare, Item[Int32].

Gäller för