語言

SiteMapNodeCollection.ReadOnly(SiteMapNodeCollection) 方法

定義

回傳一個只讀集合,包含指定 SiteMapNodeCollection 集合中的節點。

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

參數

collection
SiteMapNodeCollection

該 SiteMapNodeCollection 包含 SiteMapNode 要加入只讀的 SiteMapNodeCollection物件。

傳回

一個只讀 SiteMapNodeCollection ,元素與結構與 SiteMapNode 原始 SiteMapNodeCollection相同。

例外狀況

collection 是 null。

範例

以下程式碼範例示範如何使用該 IsReadOnly 屬性來測試集合是 SiteMapNodeCollection 唯讀或可修改。 如果 siteNodes 可修改, MoveNode 則呼叫其上;否則,會建立一個克隆 SiteMapNodeCollection ,並以此 siteNodes 為基礎。

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

備註

你可以透過檢查SiteMapNodeCollection該屬性來測試一個IsReadOnly集合是否為唯讀。 當 a IsFixedSize 為唯讀時,該true屬性也會回傳SiteMapNodeCollection。

給繼承者的注意事項

唯SiteMapNodeCollection讀集合支援讀取與搜尋操作,但不支援 、 Add(SiteMapNode)、 AddRangeClear()Insert(Int32, SiteMapNode)Remove(SiteMapNode) 、 和 方法,也不支援RemoveAt(Int32)預設索引器屬性上的設定符。 Item[Int32]

適用於