Editar

Compartir a través de


SiteMapNodeCollection.ReadOnly(SiteMapNodeCollection) Method

Definition

Returns a read-only collection that contains the nodes in the specified SiteMapNodeCollection collection.

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

Parameters

collection
SiteMapNodeCollection

The SiteMapNodeCollection that contains the SiteMapNode objects to add to the read-only SiteMapNodeCollection.

Returns

A read-only SiteMapNodeCollection with the same SiteMapNode elements and structure as the original SiteMapNodeCollection.

Exceptions

collection is null.

Examples

The following code example demonstrates how to use the IsReadOnly property to test whether a SiteMapNodeCollection collection is read-only or modifiable. If siteNodes is modifiable, MoveNode is called on it; otherwise, a clone SiteMapNodeCollection is created, using siteNodes as a 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

Remarks

You can test whether a SiteMapNodeCollection collection is read-only by checking the IsReadOnly property. The IsFixedSize property also returns true when a SiteMapNodeCollection is read-only.

Notes to Inheritors

A read-only SiteMapNodeCollection collection supports read and search operations, but does not support the Add(SiteMapNode), AddRange, Clear(), Insert(Int32, SiteMapNode), Remove(SiteMapNode), and RemoveAt(Int32) methods, nor the setter on the default indexer property, Item[Int32].

Applies to