Created
November 25, 2011 14:19
-
-
Save anonymous/1393618 to your computer and use it in GitHub Desktop.
Umbraco support for DescendantOrSelf in Razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -Nur --exclude _ReSharper.umbraco --exclude DesignTimeResolveAssemblyReferencesInput.cache --exclude '*.user' --exclude '*.suo' --exclude '*.FileListAbsolute.txt' --exclude bin --exclude obj umbraco_92d7d98ea3fe/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs umbraco_92d7d98ea3fe_mod/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs | |
--- umbraco_92d7d98ea3fe/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs 2011-09-21 11:05:44.000000000 +0200 | |
+++ umbraco_92d7d98ea3fe_mod/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNode.cs 2011-11-25 15:12:54.920000000 +0100 | |
@@ -924,6 +924,38 @@ | |
} | |
return new DynamicNodeList(new List<DynamicBackingItem>()); | |
} | |
+ public DynamicNode DescendantOrSelf() | |
+ { | |
+ return DescendantOrSelf(n => true); | |
+ } | |
+ public DynamicNode DescendantOrSelf(int level) | |
+ { | |
+ return DescendantOrSelf(node => node.Level == level); | |
+ } | |
+ public DynamicNode DescendantOrSelf(string nodeTypeAlias) | |
+ { | |
+ return DescendantOrSelf(node => node.NodeTypeAlias == nodeTypeAlias); | |
+ } | |
+ public DynamicNode DescendantOrSelf(Func<DynamicBackingItem, bool> func) | |
+ { | |
+ if (this.n != null) | |
+ { | |
+ var nodeQueue = new Queue<DynamicBackingItem>(); | |
+ nodeQueue.Enqueue(n); | |
+ while (nodeQueue.Count > 0) | |
+ { | |
+ var item = nodeQueue.Dequeue(); | |
+ if (func(item)) | |
+ return new DynamicNode(item); | |
+ | |
+ foreach (var child in item.ChildrenAsList) | |
+ { | |
+ nodeQueue.Enqueue(child); | |
+ } | |
+ } | |
+ } | |
+ return null; | |
+ } | |
public DynamicNodeList Ancestors(int level) | |
{ | |
return Ancestors(n => n.Level <= level); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment