|
[Springnet-commits] Spring.Net/src/Spring/Spring.Core/Expressions
MethodNode.cs, 1.9, 1.10
From: Aleksandar Seovic <aseovic@us...> - 2007-02-06 01:55
|
Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv22511/src/Spring/Spring.Core/Expressions
Modified Files:
MethodNode.cs
Log Message:
Fix for SPRNET-462.
Index: MethodNode.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Expressions/MethodNode.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** MethodNode.cs 5 Feb 2007 23:12:30 -0000 1.9
--- MethodNode.cs 6 Feb 2007 01:55:19 -0000 1.10
***************
*** 127,137 ****
}
- Type[] argTypes = ReflectionUtils.GetTypes(argValues);
Type contextType = (context is Type ? context as Type : context.GetType());
!
! MethodInfo mi = contextType.GetMethod(methodName, BINDING_FLAGS, null, argTypes, null);
! if (mi == null && context is Type)
{
! mi = typeof(Type).GetMethod(methodName, BINDING_FLAGS, null, argTypes, null);
}
--- 127,135 ----
}
Type contextType = (context is Type ? context as Type : context.GetType());
! MethodInfo mi = GetBestMethod(contextType, methodName, argValues);
! if (mi == null)
{
! mi = GetBestMethod(typeof(Type), methodName, argValues);
}
***************
*** 148,151 ****
--- 146,228 ----
}
}
+
+ private static MethodInfo GetBestMethod(Type type, string methodName, object[] argValues)
+ {
+ MethodInfo mi = null;
+ try
+ {
+ mi = type.GetMethod(methodName, BINDING_FLAGS);
+ }
+ catch (AmbiguousMatchException)
+ {
+
+ MethodInfo[] overloads = GetMethodsByNumberOfArguments(type, methodName, BINDING_FLAGS, argValues.Length);
+ if (overloads.Length > 0)
+ {
+ mi = GetMethodByArgumentValues(overloads, argValues);
+ }
+ }
+ return mi;
+ }
+
+ private static MethodInfo GetMethodByArgumentValues(MethodInfo[] methods, object[] argValues)
+ {
+ MethodInfo match = null;
+ int matchCount = 0;
+
+ foreach (MethodInfo method in methods)
+ {
+ ParameterInfo[] parameters = method.GetParameters();
+ bool isMatch = true;
+
+ for (int i = 0; i < parameters.Length; i++)
+ {
+ Type paramType = parameters[i].ParameterType;
+ object argValue = argValues[i];
+ if (argValue == null && paramType.IsValueType
+ || argValue != null && !paramType.IsAssignableFrom(argValue.GetType()))
+ {
+ isMatch = false;
+ break;
+ }
+ }
+
+ if (isMatch)
+ {
+ matchCount++;
+ if (matchCount == 1)
+ {
+ match = method;
+ }
+ else
+ {
+ throw new AmbiguousMatchException("Ambiguous match for method '" + method.Name +
+ "' for the specified number and types of arguments.");
+ }
+ }
+ }
+
+ return match;
+ }
+
+ private static MethodInfo[] GetMethodsByNumberOfArguments(Type type, string methodName, BindingFlags bindingFlags, int argCount)
+ {
+ MethodInfo[] methods = type.GetMethods(bindingFlags);
+ ArrayList matches = new ArrayList();
+
+ foreach (MethodInfo method in methods)
+ {
+ if (method.Name == methodName)
+ {
+ ParameterInfo[] parameters = method.GetParameters();
+ if (parameters.Length == argCount)
+ {
+ matches.Add(method);
+ }
+ }
+ }
+
+ return (MethodInfo[]) matches.ToArray(typeof(MethodInfo));
+ }
}
}
|
| Thread | Author | Date |
|---|---|---|
| [Springnet-commits] Spring.Net/src/Spring/Spring.Core/Expressions MethodNode.cs, 1.9, 1.10 | Aleksandar Seovic <aseovic@us...> |