Exemple #1
0
        public static int GetDepthLevel(this SiteMapNode node)
        {   //TODO: Unit test
            // Pre-conditions
            if (node == null)
            {
                throw new ArgumentNullException("node", "node is null.");
            }

            SiteMapNode level1Node  = node.GetParentSiteMapNodeByLevel(1); // First non-root
            int         result      = 0;                                   // parent.
            SiteMapNode currentNode = node;

            while ((currentNode.ParentNode != null) && (currentNode != level1Node)) // Count the distance to the first non-root
            {                                                                       // parent.
                result++;
                currentNode = currentNode.ParentNode;
            }
            return(++result); // increment by one because we're zero-based
        }