Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv4517/src/Spring/Spring.Core/Expressions
Modified Files:
FunctionNode.cs MethodNode.cs
Log Message:
SPRNET-898
Index: FunctionNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/FunctionNode.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FunctionNode.cs 7 Sep 2007 03:01:26 -0000 1.6
--- FunctionNode.cs 20 Mar 2008 23:58:16 -0000 1.7
***************
*** 58,63 ****
string name = this.getText();
LambdaExpressionNode lambda = evalContext.Variables[name] as LambdaExpressionNode;
! if (lambda == null)
{
throw new InvalidOperationException("Function '" + name + "' is not defined.");
--- 58,64 ----
string name = this.getText();
LambdaExpressionNode lambda = evalContext.Variables[name] as LambdaExpressionNode;
+ Delegate function = evalContext.Variables[name] as Delegate;
! if (lambda == null && function == null)
{
throw new InvalidOperationException("Function '" + name + "' is not defined.");
***************
*** 65,68 ****
--- 66,77 ----
object[] argValues = ResolveArguments(evalContext);
+
+ // delegate?
+ if (function != null)
+ {
+ return function.DynamicInvoke(argValues);
+ }
+
+ // lambda!
string[] argNames = lambda.ArgumentNames;
Index: MethodNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/MethodNode.cs,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** MethodNode.cs 6 Mar 2008 20:20:36 -0000 1.20
--- MethodNode.cs 20 Mar 2008 23:58:16 -0000 1.21
***************
*** 67,70 ****
--- 67,72 ----
collectionProcessorMap.Add("distinct", new DistinctProcessor());
collectionProcessorMap.Add("nonNull", new NonNullProcessor());
+ collectionProcessorMap.Add("convert", new ConversionProcessor());
+ collectionProcessorMap.Add("reverse", new ReverseProcessor());
}
***************
*** 100,122 ****
lock (this)
{
! // calculate checksum, if the cached method matches the current context
! if (initialized && !isCollectionProcessor)
{
! int calculatedHash = CalculateMethodHash(context.GetType(), argValues);
! initialized = (calculatedHash == methodHash);
! }
! if (!initialized)
! {
! Initialize(argValues, context);
! initialized = true;
! }
! if (isCollectionProcessor)
{
localCollectionProcessor = collectionProcessor;
}
! else
{
localMethod = method;
}
--- 102,148 ----
lock (this)
{
! if (!isCollectionProcessor)
{
! if ((context == null || context is ICollection))
! {
! string methodName = this.getText();
! // predefined collection processor?
! collectionProcessor = (ICollectionProcessor)collectionProcessorMap[methodName];
! isCollectionProcessor = (collectionProcessor != null);
! localCollectionProcessor = collectionProcessor;
! if (!isCollectionProcessor && evalContext.Variables != null)
! {
! localCollectionProcessor = evalContext.Variables[methodName] as ICollectionProcessor;
! }
! }
! }
! else
{
localCollectionProcessor = collectionProcessor;
}
!
! if (localCollectionProcessor == null)
{
+ if (context == null)
+ {
+ throw new ArgumentNullException("Context for method invocation cannot be null.");
+ }
+
+ // calculate checksum, if the cached method matches the current context
+ if (initialized)
+ {
+ int calculatedHash = CalculateMethodHash(context.GetType(), argValues);
+ initialized = (calculatedHash == methodHash);
+ }
+
+ if (!initialized)
+ {
+ string methodName = this.getText();
+ Initialize(methodName, argValues, context);
+ initialized = true;
+ }
+
localMethod = method;
}
***************
*** 126,130 ****
if (localCollectionProcessor != null)
{
! return collectionProcessor.Process((ICollection)context, argValues);
}
else
--- 152,156 ----
if (localCollectionProcessor != null)
{
! return localCollectionProcessor.Process((ICollection)context, argValues);
}
else
***************
*** 146,198 ****
}
! private void Initialize(object[] argValues, object context)
{
! string methodName = this.getText();
! if ((context == null || context is ICollection) && collectionProcessorMap.Contains(methodName))
{
! collectionProcessor = (ICollectionProcessor)collectionProcessorMap[methodName];
! isCollectionProcessor = true;
}
else
{
! if (context == null)
! {
! throw new ArgumentNullException("Context for method invocation cannot be null.");
! }
!
! Type contextType = (context is Type ? context as Type : context.GetType());
!
! // check the context type first
! MethodInfo mi = GetBestMethod(contextType, methodName, BINDING_FLAGS, argValues);
!
! // if not found, probe the Type's type
! if (mi == null)
! {
! mi = GetBestMethod(typeof(Type), methodName, BINDING_FLAGS, argValues);
! }
!
! if (mi == null)
! {
! throw new ArgumentException(
! string.Format("Method '{0}' with the specified number and types of arguments does not exist.",
! methodName));
! }
! else
{
! ParameterInfo[] parameters = mi.GetParameters();
! if (parameters.Length > 0)
{
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! isParamArray = lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0;
! if (isParamArray)
! {
! paramArrayType = lastParameter.ParameterType.GetElementType();
! argumentCount = parameters.Length;
! }
}
-
- method = new SafeMethod(mi);
- methodHash = CalculateMethodHash(contextType, argValues);
}
}
}
--- 172,210 ----
}
! private void Initialize(string methodName, object[] argValues, object context)
{
! Type contextType = (context is Type ? context as Type : context.GetType());
!
! // check the context type first
! MethodInfo mi = GetBestMethod(contextType, methodName, BINDING_FLAGS, argValues);
!
! // if not found, probe the Type's type
! if (mi == null)
{
! mi = GetBestMethod(typeof(Type), methodName, BINDING_FLAGS, argValues);
! }
!
! if (mi == null)
! {
! throw new ArgumentException(
! string.Format("Method '{0}' with the specified number and types of arguments does not exist.",
! methodName));
}
else
{
! ParameterInfo[] parameters = mi.GetParameters();
! if (parameters.Length > 0)
{
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! isParamArray = lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0;
! if (isParamArray)
{
! paramArrayType = lastParameter.ParameterType.GetElementType();
! argumentCount = parameters.Length;
}
}
+
+ method = new SafeMethod(mi);
+ methodHash = CalculateMethodHash(contextType, argValues);
}
}
|