From b0e31056a40a3c0c0c0fef3f9979b7bfe1cb5bfb Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Fri, 30 Jan 2015 22:45:08 +0700 Subject: [PATCH] Fixes #375, TrimEmptyGroupingNodesVisibilityProvider doesn't work with nested visibility providers. --- .../TrimEmptyGroupingNodesVisibilityProvider.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs index 239b03a5..46623d03 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs @@ -1,21 +1,25 @@ using System; using System.Collections.Generic; +using System.Linq; namespace MvcSiteMapProvider { /// - /// Removes non-clickable nodes that have no accessible children. + /// Removes non-clickable nodes that have no accessible and/or visible children. /// public class TrimEmptyGroupingNodesVisibilityProvider : SiteMapNodeVisibilityProviderBase { public override bool IsVisible(ISiteMapNode node, IDictionary sourceMetadata) { - if (!node.HasChildNodes && !node.Clickable) + // Optimization - return quickly if clickable. + if (node.Clickable) { - return false; + return true; } - return true; + + var childNodes = node.ChildNodes; + return childNodes == null || childNodes.Any(c => c.IsVisible(sourceMetadata)); } } }