SiteMapNode.Clone Metoda

Definicja

Tworzy nowy węzeł, który jest kopią bieżącego węzła.

Przeciążenia

Nazwa Opis
Clone()

Tworzy nowy węzeł, który jest kopią bieżącego węzła.

Clone(Boolean)

Tworzy nową kopię, która jest kopią bieżącego węzła, opcjonalnie klonując wszystkie węzły nadrzędne i węzły nadrzędne bieżącego węzła.

Clone()

Tworzy nowy węzeł, który jest kopią bieżącego węzła.

public:
 virtual System::Web::SiteMapNode ^ Clone();
public virtual System.Web.SiteMapNode Clone();
abstract member Clone : unit -> System.Web.SiteMapNode
override this.Clone : unit -> System.Web.SiteMapNode
Public Overridable Function Clone () As SiteMapNode

Zwraca

Nowy węzeł, który jest kopią bieżącego węzła.

Uwagi

Wywołuje metodę Clone z parametrem ustawionym na false. Dostawca, Title, Url, Descriptioni Key właściwości są kopiowane. Kolekcje Roles i Attributes są kopiowane do nowych kolekcji. Węzły nadrzędne i węzły podrzędne nie są klonowane.

Zobacz też

Dotyczy

Clone(Boolean)

Tworzy nową kopię, która jest kopią bieżącego węzła, opcjonalnie klonując wszystkie węzły nadrzędne i węzły nadrzędne bieżącego węzła.

public:
 virtual System::Web::SiteMapNode ^ Clone(bool cloneParentNodes);
public virtual System.Web.SiteMapNode Clone(bool cloneParentNodes);
abstract member Clone : bool -> System.Web.SiteMapNode
override this.Clone : bool -> System.Web.SiteMapNode
Public Overridable Function Clone (cloneParentNodes As Boolean) As SiteMapNode

Parametry

cloneParentNodes
Boolean

true aby sklonować wszystkie węzły nadrzędne i węzły nadrzędne bieżącego węzła; w przeciwnym razie, false.

Zwraca

Nowy węzeł, który jest kopią bieżącego węzła.

Przykłady

W poniższym przykładzie kodu pokazano, jak wywołać metodę Clone w celu utworzenia zduplikowanego węzła mapy witryny z bieżącego węzła. Metoda jest zarejestrowana ExpandForumPaths w celu obsługi SiteMapResolve zdarzenia. Używa Clone metody do utworzenia działającej kopii bieżącego węzła mapy witryny, zmodyfikowania atrybutów na podstawie danych personalizacji i zwrócenia działającej kopii.

private void Page_Load(object sender, EventArgs e)
{
    // The ExpandForumPaths method is called to handle
    // the SiteMapResolve event.
    SiteMap.SiteMapResolve +=
      new SiteMapResolveEventHandler(this.ExpandForumPaths);
}

private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
    // The current node represents a Post page in a bulletin board forum.
    // Clone the current node and all of its relevant parents. This
    // returns a site map node that a developer can then
    // walk, modifying each node.Url property in turn.
    // Since the cloned nodes are separate from the underlying
    // site navigation structure, the fixups that are made do not
    // effect the overall site navigation structure.
    SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
    SiteMapNode tempNode = currentNode;

    // Obtain the recent IDs.
    int forumGroupID = GetMostRecentForumGroupID();
    int forumID = GetMostRecentForumID(forumGroupID);
    int postID = GetMostRecentPostID(forumID);

    // The current node, and its parents, can be modified to include
    // dynamic querystring information relevant to the currently
    // executing request.
    if (0 != postID)
    {
        tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumID))
    {
        tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumGroupID))
    {
        tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
    }

    return currentNode;
}
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' The ExpandForumPaths method is called to handle
    ' the SiteMapResolve event.
    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

End Sub

Private Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
    ' The current node represents a Post page in a bulletin board forum.
    ' Clone the current node and all of its relevant parents. This
    ' returns a site map node that a developer can then
    ' walk, modifying each node.Url property in turn.
    ' Since the cloned nodes are separate from the underlying
    ' site navigation structure, the fixups that are made do not
    ' effect the overall site navigation structure.
    Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
    Dim tempNode As SiteMapNode = currentNode

    ' Obtain the recent IDs.
    Dim forumGroupID As Integer = GetMostRecentForumGroupID()
    Dim forumID As Integer = GetMostRecentForumID(forumGroupID)
    Dim postID As Integer = GetMostRecentPostID(forumID)

    ' The current node, and its parents, can be modified to include
    ' dynamic querystring information relevant to the currently
    ' executing request.
    If Not (0 = postID) Then
        tempNode.Url = tempNode.Url & "?PostID=" & postID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = forumID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumID=" & forumID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = ForumGroupID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumGroupID=" & forumGroupID.ToString()
    End If

    Return currentNode

End Function

Uwagi

cloneParentNodes Jeśli parametr to true, Clone metoda rekursywnie klonuje wszystkie węzły bezpośrednich przodków i kojarzy je z bieżącym sklonowanym węzłem. Węzły podrzędne nie są klonowane.

Kolekcje Roles i Attributes są stosowane do nowych kolekcji.

Zobacz też

Dotyczy