src/GenFx.Components/Trees/TreeHelper.cs
/// <summary>
/// Swaps the position of the two nodes within their respective trees.
/// </summary>
/// <remarks><paramref name="node1"/> will be removed from its tree and be placed in the
/// position that <paramref name="node2"/> existed in its tree; and vice versa.</remarks>
/// <param name="node1"><see cref="TreeNode"/> to be swapped with <paramref name="node2"/>.</param>
/// <param name="node2"><see cref="TreeNode"/> to be swapped with <paramref name="node1"/>.</param>
/// <exception cref="ArgumentNullException"><paramref name="node1"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="node2"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="node1"/> is not contained by this tree.</exception>
/// <exception cref="ArgumentException"><paramref name="node1"/> does not have a tree assigned.</exception>
/// <exception cref="ArgumentException"><paramref name="node2"/> does not have a tree assigned.</exception>
Swaps the position of the two nodes within their respective trees.
Swaps the position of the two nodes within their respective trees .
public static void Swap(TreeNode node1, TreeNode node2)
        {
            if (node1 == null)
            {
                throw new ArgumentNullException(nameof(node1));
            }
            if (node2 == null)
            {
                throw new ArgumentNullException(nameof(node2));
            }
            TreeNode? node2ParentNode = node2.ParentNode;
            TreeEntityBase? node2Tree = node2.Tree;
            TreeNode? node1ParentNode = node1.ParentNode;
            TreeEntityBase? node1Tree = node1.Tree;
            if (node1Tree is null)
            {
                throw new ArgumentException(Resources.NodeTreeNotSet, nameof(node1));
            }
            if (node2Tree is null)
            {
                throw new ArgumentException(Resources.NodeTreeNotSet, nameof(node2));
            }
            TreeHelper.ReplaceNodeInTree(node1, node2Tree, node2, node2ParentNode);
            TreeHelper.ReplaceNodeInTree(node2, node1Tree, node1, node1ParentNode);
        }
public static void Swap ( TreeNode node1 , TreeNode node2 ) { if ( node1 == null ) { throw new ArgumentNullException ( nameof ( node1 ) ) ; } if ( node2 == null ) { throw new ArgumentNullException ( nameof ( node2 ) ) ; } TreeNode ? node2ParentNode = node2 . ParentNode ; TreeEntityBase ? node2Tree = node2 . Tree ; TreeNode ? node1ParentNode = node1 . ParentNode ; TreeEntityBase ? node1Tree = node1 . Tree ; if ( node1Tree is null ) { throw new ArgumentException ( Resources . NodeTreeNotSet , nameof ( node1 ) ) ; } if ( node2Tree is null ) { throw new ArgumentException ( Resources . NodeTreeNotSet , nameof ( node2 ) ) ; } TreeHelper . ReplaceNodeInTree ( node1 , node2Tree , node2 , node2ParentNode ) ; TreeHelper . ReplaceNodeInTree ( node2 , node1Tree , node1 , node1ParentNode ) ; }
Swaps the position of the two nodes within their respective trees.
Swaps the position of the two nodes within their respective trees .
None
None
None
does not have a tree assigned.
does not have a tree assigned .
does not have a tree assigned.
does not have a tree assigned .
node1
TreeNode
to be swapped with .
to be swapped with .
node2
TreeNode
to be swapped with .
to be swapped with .
remarks
will be removed from its tree and be placed in the
position that  existed in its tree; and vice versa.
will be removed from its tree and be placed in the position that existed in its tree ; and vice versa .