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,包含要加入至唯讀 SiteMapNodeSiteMapNodeCollection 物件。

傳回

SiteMapNodeCollection

唯讀 SiteMapNodeCollection,具有與原始 SiteMapNode 相同的 SiteMapNodeCollection 項目和結構。

例外狀況

collectionnull

範例

下列程式碼範例示範如何使用 IsReadOnly 屬性來測試 SiteMapNodeCollection 集合是唯讀還是可修改的。 如果 siteNodes 可修改, MoveNode 則會在它上呼叫 ,否則會使用 siteNodes 做為基底來建立複製 SiteMapNodeCollection 品。

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

備註

您可以藉由檢查 IsReadOnly 屬性來測試集合是否 SiteMapNodeCollection 為唯讀。 當 是唯讀時 SiteMapNodeCollection ,屬性 IsFixedSize 也會傳 true 回 。

給繼承者的注意事項

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

適用於