internal static object Call(IntPtr instance, string name, object[] args) { Contract.Requires(instance != IntPtr.Zero, "instance is zero"); object result; if (name == "alloc" && args.Length == 0) // need this so we can create an auto release pool without leaking NSMethodSignature { IntPtr exception = IntPtr.Zero; IntPtr ip = DirectCalls.Callp(instance, Selector.Alloc, ref exception); if (exception != IntPtr.Zero) { CocoaException.Raise(exception); } result = NSObject.Lookup(ip); } else { Selector selector = new Selector(name); MethodSignature sig = new MethodSignature(instance, (IntPtr)selector); Native native = new Native(instance, selector, sig); native.SetArgs(args); result = native.Invoke(); } return(result); }
/// <summary>Dynamic call to an exported type's base class method.</summary> /// <param name = "baseClass">The class for the type (or a descendent of the type) containing the method you want to call.</param> /// <param name = "name">A method name, e.g. "setFrame:display:".</param> /// <param name = "args">The arguments to pass to the method. If the arity or argument types /// don't match the unmanaged code an exception will be thrown.</param> public object SuperCall(Class baseClass, string name, params object[] args) { Contract.Requires(baseClass != null, "baseClass is null"); Contract.Requires(!string.IsNullOrEmpty(name), "name is null or empty"); Contract.Requires(!m_deallocated, "ref count is zero"); object result = IntPtr.Zero; if (m_instance != IntPtr.Zero) { Native native = new Native(m_instance, new Selector(name), baseClass); native.SetArgs(args); result = native.Invoke(); } return(result); }
/// <summary>Allows Call expressions to be chained.</summary> public static object Call(this object instance, Selector selector, params object[] args) { Contract.Requires(selector != null, "selector is null"); Contract.Requires(args != null, "args is null"); object result = new NSObject(IntPtr.Zero); if (instance != null) { IntPtr ptr; if (instance.GetType() == typeof(IntPtr)) { ptr = (IntPtr)instance; } else { ptr = (IntPtr)(NSObject)instance; } if (selector.Name == "init" && args.Length == 0) { IntPtr exception = IntPtr.Zero; IntPtr ip = DirectCalls.Callp(ptr, Selector.Init, ref exception); if (exception != IntPtr.Zero) { CocoaException.Raise(exception); } result = NSObject.Lookup(ip); } else { Native invoke = new Native(ptr, selector); invoke.SetArgs(args); result = invoke.Invoke(); } } return(result); }
internal static object Call(IntPtr instance, string name, object[] args) { Contract.Requires(instance != IntPtr.Zero, "instance is zero"); object result; if (name == "alloc" && args.Length == 0) // need this so we can create an auto release pool without leaking NSMethodSignature { IntPtr exception = IntPtr.Zero; IntPtr ip = DirectCalls.Callp(instance, Selector.Alloc, ref exception); if (exception != IntPtr.Zero) CocoaException.Raise(exception); result = NSObject.Lookup(ip); } else { Selector selector = new Selector(name); MethodSignature sig = new MethodSignature(instance, (IntPtr) selector); Native native = new Native(instance, selector, sig); native.SetArgs(args); result = native.Invoke(); } return result; }