summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-05-09 12:47:02 +0000
committerRich Hickey <richhickey@gmail.com>2006-05-09 12:47:02 +0000
commitc403c6e6f13d19e43d4f7dbab9dcb40fe9781f76 (patch)
tree4808653b73f6048bd65d77d879f7e1a795d1e599
parent03ede1f5cd8d7919edd3543385da36f985cd0c17 (diff)
added ctor/new support
-rw-r--r--src/cli/runtime/Reflector.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cli/runtime/Reflector.cs b/src/cli/runtime/Reflector.cs
index d4bf11bf..a23a305f 100644
--- a/src/cli/runtime/Reflector.cs
+++ b/src/cli/runtime/Reflector.cs
@@ -39,9 +39,35 @@ public static Object invokeInstanceMethod(String name, Object target, Object[] a
}
}
+public static Object invokeConstructor(Type t, Object[] args) //throws Exception
+ {
+ ConstructorInfo[] allctors = t.GetConstructors();
+ ArrayList ctors = new ArrayList();
+ foreach (ConstructorInfo ctor in allctors)
+ {
+ if (ctor.GetParameters().Length == args.Length)
+ ctors.Add(ctor);
+ }
+ if (ctors.Count == 0)
+ {
+ throw new InvalidOperationException("No matching ctor found");
+ }
+ else if (ctors.Count == 1)
+ {
+ ConstructorInfo ctor = (ConstructorInfo)ctors[0];
+ return ctor.Invoke(boxArgs(ctor.GetParameters(), args));
+ }
+ else //overloaded w/same arity, let reflection choose most specific match
+ {
+ return t.InvokeMember(null, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance,
+ null, null, args);
+ }
+ }
public static Object invokeStaticMethod(String name, String className, Object[] args) //throws Exception
{
Type t = Type.GetType(className);
+ if (name.Equals("new"))
+ return invokeConstructor(t, args);
IList methods = getMethods(t, args.Length, name, true);
return invokeMatchingMethod(name, null, args, t, methods,true);
}