/// /// Invokes the named method of the specified target object. /// /// The target object /// The method name /// Specifies which arguments must be passed by reference. /// The method arguments /// /// /// /// // /// // calling method string Test(string arg1, ref object arg2); /// // /// SomeObject x = new SomeObject(); /// string s = (string) Introspect.InvokeMethod(o, "Test", /// new bool[] {false, true}, new object[] {"hi!", x}); /// /// public static object InvokeMethod(object target, string methodName, bool[] byRef, object[] args) { if (byRef.Length != args.Length) throw new ArgumentException("Length of byRef and args must match.", "byRef, args"); ParameterModifier[] mods = new ParameterModifier[byRef.Length]; for (int i = 0; i < byRef.Length; i++) { ParameterModifier m = new ParameterModifier(1); m[0] = byRef[i]; mods[i] = m; } return target.GetType().InvokeMember( methodName, BindingFlags.InvokeMethod, null, target, args, mods, null, null ); }