diff --git a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs
index 9a50477191..94e168140e 100644
--- a/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs
+++ b/ICSharpCode.NRefactory/CSharp/Ast/CompilationUnit.cs
@@ -25,6 +25,9 @@
// THE SOFTWARE.
using System;
using System.Collections.Generic;
+using System.Linq;
+
+using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.CSharp
{
@@ -101,6 +104,21 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
+ ///
+ /// Gets all nodes in that are satisfing a predicate.
+ ///
+ /// Predicate to filter the nodes.
+ ///
+ public IEnumerable GetNodesWithLineNumbers(Predicate predicate)
+ {
+ if (predicate == null)
+ throw new ArgumentNullException("predicate");
+
+ return TreeTraversal
+ .PreOrder((AstNode)this, n => n.Children)
+ .Where(n => predicate(n) && n.Annotation>() != null);
+ }
+
public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitCompilationUnit (this, data);