Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19074
Modified Files:
BaseNode.cs LambdaExpressionNode.cs LocalFunctionNode.cs
NodeWithArguments.cs ProjectionNode.cs SelectionFirstNode.cs
SelectionLastNode.cs SelectionNode.cs VariableNode.cs
Log Message:
fixed SPRNET-709
Index: LambdaExpressionNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/LambdaExpressionNode.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** LambdaExpressionNode.cs 16 May 2007 15:09:41 -0000 1.6
--- LambdaExpressionNode.cs 23 Aug 2007 23:30:52 -0000 1.7
***************
*** 100,108 ****
public object GetValueInternal(object context, EvaluationContext evalContext, IDictionary arguments)
{
! IDictionary savedLocalVariables = evalContext.LocalVariables;
! evalContext.LocalVariables = arguments;
! object result = base.GetValueInternal(context, evalContext);
! evalContext.LocalVariables = savedLocalVariables;
! return result;
}
--- 100,108 ----
public object GetValueInternal(object context, EvaluationContext evalContext, IDictionary arguments)
{
! using (evalContext.SwitchLocalVariables(arguments))
! {
! object result = base.GetValueInternal(context, evalContext);
! return result;
! }
}
Index: VariableNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/VariableNode.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** VariableNode.cs 16 May 2007 15:09:41 -0000 1.6
--- VariableNode.cs 23 Aug 2007 23:30:53 -0000 1.7
***************
*** 58,62 ****
if (varName == "this")
{
! return evalContext.CurrentContext;
}
else if (varName == "root")
--- 58,62 ----
if (varName == "this")
{
! return evalContext.ThisContext;
}
else if (varName == "root")
Index: SelectionFirstNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/SelectionFirstNode.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SelectionFirstNode.cs 16 May 2007 15:09:41 -0000 1.3
--- SelectionFirstNode.cs 23 Aug 2007 23:30:53 -0000 1.4
***************
*** 64,73 ****
BaseNode expression = (BaseNode) this.getFirstChild();
! foreach (object o in enumerable)
{
! bool isMatch = (bool) expression.GetValueInternal(o, evalContext);
! if (isMatch)
{
! return o;
}
}
--- 64,77 ----
BaseNode expression = (BaseNode) this.getFirstChild();
! using (evalContext.SwitchThisContext())
{
! foreach (object o in enumerable)
{
! evalContext.ThisContext = o;
! bool isMatch = (bool) expression.GetValueInternal(o, evalContext);
! if (isMatch)
! {
! return o;
! }
}
}
Index: BaseNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/BaseNode.cs,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** BaseNode.cs 22 Aug 2007 20:16:20 -0000 1.22
--- BaseNode.cs 23 Aug 2007 23:30:52 -0000 1.23
***************
*** 33,36 ****
--- 33,38 ----
public abstract class BaseNode : SpringAST, IExpression
{
+ #region EvaluationContext class
+
/// <summary>
/// Holds the state during evaluating an expression.
***************
*** 38,42 ****
protected internal class EvaluationContext
{
! /// <summary>
/// Gets/Sets the root context of the current evaluation
/// </summary>
--- 40,83 ----
protected internal class EvaluationContext
{
! #region Holder classes
!
! private class ThisContextHolder : IDisposable
! {
! private readonly EvaluationContext owner;
! private readonly object savedThisContext;
!
! public ThisContextHolder(EvaluationContext owner)
! {
! this.owner = owner;
! this.savedThisContext = owner.ThisContext;
! }
!
! public void Dispose()
! {
! owner.ThisContext = savedThisContext;
! }
! }
!
! private class LocalVariablesHolder : IDisposable
! {
! private readonly EvaluationContext owner;
! private readonly IDictionary savedLocalVariables;
!
! public LocalVariablesHolder(EvaluationContext owner, IDictionary newLocalVariables)
! {
! this.owner = owner;
! this.savedLocalVariables = owner.LocalVariables;
! owner.LocalVariables = newLocalVariables;
! }
!
! public void Dispose()
! {
! owner.LocalVariables = savedLocalVariables;
! }
! }
!
! #endregion
!
! /// <summary>
/// Gets/Sets the root context of the current evaluation
/// </summary>
***************
*** 49,53 ****
/// Gets/Sets the current context of the current evaluation
/// </summary>
! public object CurrentContext;
/// <summary>
/// Gets/Sets global variables of the current evaluation
--- 90,94 ----
/// Gets/Sets the current context of the current evaluation
/// </summary>
! public object ThisContext;
/// <summary>
/// Gets/Sets global variables of the current evaluation
***************
*** 59,70 ****
public IDictionary LocalVariables;
! public EvaluationContext(object rootContext, IDictionary variables)
{
this.RootContext = rootContext;
! this.CurrentContext = rootContext;
! this.Variables = variables;
}
}
/// <summary>
/// Create a new instance
--- 100,134 ----
public IDictionary LocalVariables;
! /// <summary>
! /// Initializes a new EvaluationContext instance.
! /// </summary>
! /// <param name="rootContext">The root context for this evaluation</param>
! /// <param name="globalVariables">dictionary of global variables used during this evaluation</param>
! public EvaluationContext(object rootContext, IDictionary globalVariables)
{
this.RootContext = rootContext;
! this.ThisContext = rootContext;
! this.Variables = globalVariables;
! }
!
! /// <summary>
! /// Switches current ThisContext.
! /// </summary>
! public IDisposable SwitchThisContext()
! {
! return new ThisContextHolder(this);
! }
!
! /// <summary>
! /// Switches current LocalVariables.
! /// </summary>
! public IDisposable SwitchLocalVariables(IDictionary newLocalVariables)
! {
! return new LocalVariablesHolder(this, newLocalVariables);
}
}
+ #endregion
+
/// <summary>
/// Create a new instance
***************
*** 128,132 ****
protected internal object GetValueInternal(object context, EvaluationContext evalContext)
{
- evalContext.CurrentContext = context;
return Get(context, evalContext);
}
--- 192,195 ----
***************
*** 173,177 ****
protected internal void SetValueInternal(object context, EvaluationContext evalContext, object newValue)
{
- evalContext.CurrentContext = context;
Set(context, evalContext, newValue);
}
--- 236,239 ----
Index: SelectionNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/SelectionNode.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SelectionNode.cs 16 May 2007 15:09:41 -0000 1.3
--- SelectionNode.cs 23 Aug 2007 23:30:53 -0000 1.4
***************
*** 66,75 ****
BaseNode expression = (BaseNode) this.getFirstChild();
IList selectionList = new ArrayList();
! foreach (object o in enumerable)
{
! bool isMatch = (bool) expression.GetValueInternal(o, evalContext);
! if (isMatch)
{
! selectionList.Add(o);
}
}
--- 66,79 ----
BaseNode expression = (BaseNode) this.getFirstChild();
IList selectionList = new ArrayList();
! using (evalContext.SwitchThisContext())
{
! foreach (object o in enumerable)
{
! evalContext.ThisContext = o;
! bool isMatch = (bool) expression.GetValueInternal(o, evalContext);
! if (isMatch)
! {
! selectionList.Add(o);
! }
}
}
Index: LocalFunctionNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/LocalFunctionNode.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** LocalFunctionNode.cs 16 May 2007 15:09:41 -0000 1.5
--- LocalFunctionNode.cs 23 Aug 2007 23:30:52 -0000 1.6
***************
*** 57,61 ****
{
string name = this.getText();
! IDictionary locals = evalContext.LocalVariables; //(IDictionary) variables[LocalVariableNode.LOCAL_VARIABLES];
LambdaExpressionNode lambda = locals[name] as LambdaExpressionNode;
--- 57,61 ----
{
string name = this.getText();
! IDictionary locals = evalContext.LocalVariables;
LambdaExpressionNode lambda = locals[name] as LambdaExpressionNode;
Index: ProjectionNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/ProjectionNode.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ProjectionNode.cs 16 May 2007 15:09:41 -0000 1.6
--- ProjectionNode.cs 23 Aug 2007 23:30:53 -0000 1.7
***************
*** 66,72 ****
BaseNode expression = (BaseNode) this.getFirstChild();
IList projectedList = new ArrayList();
! foreach(object o in enumerable)
{
! projectedList.Add(expression.GetValueInternal(o, evalContext));
}
return projectedList;
--- 66,76 ----
BaseNode expression = (BaseNode) this.getFirstChild();
IList projectedList = new ArrayList();
! using (evalContext.SwitchThisContext())
{
! foreach(object o in enumerable)
! {
! evalContext.ThisContext = o;
! projectedList.Add(expression.GetValueInternal(o, evalContext));
! }
}
return projectedList;
Index: NodeWithArguments.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/NodeWithArguments.cs,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** NodeWithArguments.cs 31 Jul 2007 08:18:20 -0000 1.13
--- NodeWithArguments.cs 23 Aug 2007 23:30:52 -0000 1.14
***************
*** 158,162 ****
else
{
! return ((BaseNode)args[position]).GetValueInternal(evalContext.CurrentContext, evalContext);
}
}
--- 158,162 ----
else
{
! return ((BaseNode)args[position]).GetValueInternal(evalContext.ThisContext, evalContext);
}
}
***************
*** 170,174 ****
private object ResolveNamedArgument(string name, EvaluationContext evalContext)
{
! return ((BaseNode)namedArgs[name]).GetValueInternal(evalContext.CurrentContext, evalContext);
}
--- 170,174 ----
private object ResolveNamedArgument(string name, EvaluationContext evalContext)
{
! return ((BaseNode)namedArgs[name]).GetValueInternal(evalContext.ThisContext, evalContext);
}
Index: SelectionLastNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/SelectionLastNode.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SelectionLastNode.cs 16 May 2007 15:09:41 -0000 1.3
--- SelectionLastNode.cs 23 Aug 2007 23:30:53 -0000 1.4
***************
*** 64,75 ****
}
! BaseNode expression = (BaseNode) this.getFirstChild();
! for (int i = list.Count - 1; i >= 0; i--)
{
! object listItem = list[i];
! bool isMatch = (bool)expression.GetValueInternal( listItem, evalContext );
! if (isMatch)
{
! return listItem;
}
}
--- 64,79 ----
}
! using (evalContext.SwitchThisContext())
{
! BaseNode expression = (BaseNode) this.getFirstChild();
! for (int i = list.Count - 1; i >= 0; i--)
{
! object listItem = list[i];
! evalContext.ThisContext = listItem;
! bool isMatch = (bool)expression.GetValueInternal( listItem, evalContext );
! if (isMatch)
! {
! return listItem;
! }
}
}
|