internal object invoke(object instance, object[] args) { if (m_reflect == null) m_parent.finish(); try { // zero index is full signature up to using max defaults int index = m_params.sz()-args.Length; if (m_parent.dotnetRepr() && isInstance()) index++; if (index < 0) index = 0; MethodInfo m = m_reflect[index]; //System.Console.WriteLine(">>> " + m_reflect.Length + "/" + index); //System.Console.WriteLine(m_reflect[index]); //System.Console.WriteLine("---"); //for (int i=0; i<m_reflect.Length; i++) // System.Console.WriteLine(m_reflect[i]); // TODO - not sure how this should work entirely yet, but we need // to be responsible for "boxing" Fantom wrappers and primitives // box the parameters ParameterInfo[] pars = m.GetParameters(); for (int i=0; i<args.Length; i++) { System.Type pt = pars[i].ParameterType; if (pt == boolPrimitive && args[i] is Fan.Sys.Boolean) { args[i] = (args[i] as Fan.Sys.Boolean).booleanValue(); } else if (pt == doublePrimitive && args[i] is Fan.Sys.Double) { args[i] = (args[i] as Fan.Sys.Double).doubleValue(); } else if (pt == longPrimitive && args[i] is Fan.Sys.Long) { args[i] = (args[i] as Fan.Sys.Long).longValue(); } } // invoke method object ret = m.Invoke(instance, args); // box the return value return FanUtil.box(ret); } catch (ArgumentException e) { throw ArgErr.make(e).val; } catch (TargetInvocationException e) { Err err = Err.make(e.InnerException); err.m_stack = e.InnerException.StackTrace; throw err.val; } catch (Exception e) { if (m_reflect == null) throw Err.make("Method not mapped to System.Reflection.MethodInfo correctly " + m_qname).val; /* System.Console.WriteLine("ERROR: " + signature()); System.Console.WriteLine(" instance: " + instance); System.Console.WriteLine(" args: " + (args == null ? "null" : ""+args.Length)); for (int i=0; args != null && i<args.Length; ++i) System.Console.WriteLine(" args[" + i + "] = " + args[i]); Err.dumpStack(e); */ throw Err.make("Cannot call '" + this + "': " + e).val; } }
void complexAdd(Type t, object obj, Method addMethod, object val, int line) { try { addMethod.invoke(obj, new object[] { val }); } catch (System.Exception ex) { throw err("Cannot call " + t.qname() + ".add: " + ex, line, ex); } }