SiteMapNode.Clone Metod

Definition

Skapar en ny nod som är en kopia av den aktuella noden.

Överlagringar

Name Description
Clone()

Skapar en ny nod som är en kopia av den aktuella noden.

Clone(Boolean)

Skapar en ny kopia som är en kopia av den aktuella noden, om du vill klona alla överordnade och överordnade noder för den aktuella noden.

Clone()

Skapar en ny nod som är en kopia av den aktuella noden.

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

Returer

En ny nod som är en kopia av den aktuella noden.

Kommentarer

Clone Anropar metoden med parametern inställd på false. Egenskaperna provider, Title, Url, Descriptionoch Key kopieras. Samlingarna Roles och Attributes kopieras till nya samlingar. Överordnade och underordnade noder klonas inte.

Se även

Gäller för

Clone(Boolean)

Skapar en ny kopia som är en kopia av den aktuella noden, om du vill klona alla överordnade och överordnade noder för den aktuella noden.

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

Parametrar

cloneParentNodes
Boolean

trueför att klona alla överordnade och överordnade noder i den aktuella noden. annars . false

Returer

En ny nod som är en kopia av den aktuella noden.

Exempel

Följande kodexempel visar hur du anropar Clone metoden för att skapa en duplicerad platsöversiktsnod från den aktuella noden. Metoden ExpandForumPaths är registrerad för att hantera händelsen SiteMapResolve . Den använder Clone metoden för att skapa en fungerande kopia av den aktuella platsöversiktsnoden, ändra attribut baserat på anpassningsdata och returnera arbetskopian.

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

Kommentarer

Om parametern cloneParentNodes är trueClone klonar metoden rekursivt alla direkta överordnade noder och associerar dem med den aktuella klonade noden. Underordnade noder klonas inte.

Samlingarna Roles och Attributes tillämpas på nya samlingar.

Se även

Gäller för