Permalink
Browse files

Linq: Added an expression visitor that provides access to parent node…

…s while visiting.

SVN: trunk@5276
  • Loading branch information...
1 parent 37f331f commit 23febdea541113680f34d630c673ac2b35f58b84 @patearl patearl committed Nov 28, 2010
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using NHibernate.Linq.Visitors;
+
+namespace NHibernate.Linq
+{
+ public class ContextualNhExpressionTreeVisitor : NhExpressionTreeVisitor
+ {
+ private Stack<VisitorContext> _contextStack;
+
+ public ContextualNhExpressionTreeVisitor()
+ {
+ _contextStack = new Stack<VisitorContext>();
+ _contextStack.Push(null);
+ }
+
+ public override Expression VisitExpression(Expression expression)
+ {
+ if (expression == null)
+ return null;
+
+ VisitorContext context = new VisitorContext(_contextStack.Peek(), expression);
+ _contextStack.Push(context);
+
+ Expression result = base.VisitExpression(expression);
+
+ _contextStack.Pop();
+
+ return result;
+ }
+
+ protected VisitorContext Context
+ {
+ get { return _contextStack.Peek(); }
+ }
+ }
+}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+
+namespace NHibernate.Linq.Visitors
+{
+ public class VisitorContext
+ {
+ public VisitorContext(VisitorContext parent, Expression expression)
+ {
+ Parent = parent;
+ Expression = expression;
+ }
+
+ public VisitorContext Parent { get; private set; }
+ public Expression Expression { get; private set; }
+ }
+}
@@ -241,6 +241,8 @@
<Compile Include="ISessionFactory.cs" />
<Compile Include="ITransaction.cs" />
<Compile Include="LazyInitializationException.cs" />
+ <Compile Include="Linq\Visitors\ContextualNhExpressionTreeVisitor.cs" />
+ <Compile Include="Linq\Visitors\VisitorContext.cs" />
<Compile Include="Loader\Loader.cs" />
<Compile Include="Loader\OuterJoinLoader.cs" />
<Compile Include="LockMode.cs" />

0 comments on commit 23febde

Please sign in to comment.