Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>Dynamic call to an exported type&apos;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. &quot;setFrame:display:&quot;.</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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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;
        }