コード例 #1
0
 public extern static void void_objc_msgSend_IntPtr_ref_BlockLiteral(IntPtr receiver, IntPtr selector, IntPtr p1, ref BlockLiteral p2);
コード例 #2
0
        internal static IntPtr GetBlockForDelegate(MethodInfo minfo, object @delegate, uint token_ref, string signature)
        {
            if (@delegate == null)
            {
                return(IntPtr.Zero);
            }

            if (!(@delegate is Delegate))
            {
                throw ErrorHelper.CreateError(8016, $"Unable to convert delegate to block for the return value for the method {minfo.DeclaringType.FullName}.{minfo.Name}, because the input isn't a delegate, it's a {@delegate.GetType ().FullName}. {Constants.PleaseFileBugReport}");
            }

            Type delegateProxyType = GetDelegateProxyType(minfo, token_ref, out var baseMethod);

            if (baseMethod == null)
            {
                baseMethod = minfo;                 // 'baseMethod' is only used in error messages, and if it's null, we just use the closest alternative we have (minfo).
            }
            if (delegateProxyType == null)
            {
                throw ErrorHelper.CreateError(8012, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: DelegateType is null. {Constants.PleaseFileBugReport}");
            }

            var delegateProxyField = delegateProxyType.GetField("Handler", BindingFlags.NonPublic | BindingFlags.Static);

            if (delegateProxyField == null)
            {
                throw ErrorHelper.CreateError(8013, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: DelegateType ({delegateProxyType.FullName}) specifies a type without a 'Handler' field. {Constants.PleaseFileBugReport}");
            }

            var handlerDelegate = delegateProxyField.GetValue(null);

            if (handlerDelegate == null)
            {
                throw ErrorHelper.CreateError(8014, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: The DelegateType's ({delegateProxyType.FullName}) 'Handler' field is null. {Constants.PleaseFileBugReport}");
            }

            if (!(handlerDelegate is Delegate))
            {
                throw ErrorHelper.CreateError(8015, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: The DelegateType's ({delegateProxyType.FullName}) 'Handler' field is not a delegate, it's a {handlerDelegate.GetType ().FullName}. {Constants.PleaseFileBugReport}");
            }

            // We now have the information we need to create the block.
            // Note that we must create a heap-allocated block, so we
            // start off by creating a stack-allocated block, and then
            // call _Block_copy, which will create a heap-allocated block
            // with the proper reference count.
            BlockLiteral block = new BlockLiteral();

            if (signature == null)
            {
                if (Runtime.DynamicRegistrationSupported)
                {
                    block.SetupBlock((Delegate)handlerDelegate, (Delegate)@delegate);
                }
                else
                {
                    throw ErrorHelper.CreateError(8026, $"BlockLiteral.GetBlockForDelegate with a null signature is not supported when the dynamic registrar has been linked away (delegate type: {@delegate.GetType ().FullName}).");
                }
            }
            else
            {
                block.SetupBlockImpl((Delegate)handlerDelegate, (Delegate)@delegate, true, signature);
            }
            var rv = _Block_copy(ref block);

            block.CleanupBlock();
            return(rv);
        }
コード例 #3
0
 internal static extern IntPtr _Block_copy(ref BlockLiteral block);
コード例 #4
0
        internal static IntPtr GetBlockForDelegate(MethodInfo minfo, object @delegate, string signature)
        {
            if (@delegate == null)
            {
                return(IntPtr.Zero);
            }

            if (!(@delegate is Delegate))
            {
                throw ErrorHelper.CreateError(8016, "Unable to convert delegate to block for the return value for the method {0}.{1}, because the input isn't a delegate, it's a {1}. Please file a bug at http://bugzilla.xamarin.com.", minfo.DeclaringType.FullName, minfo.Name, @delegate.GetType().FullName);
            }

            var baseMethod = minfo.GetBaseDefinition();

            var delegateProxies = baseMethod.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(DelegateProxyAttribute), false);

            if (delegateProxies.Length == 0)
            {
                throw ErrorHelper.CreateError(8011, "Unable to locate the delegate to block conversion attribute ([DelegateProxy]) for the return value for the method {0}.{1}. Please file a bug at http://bugzilla.xamarin.com.", baseMethod.DeclaringType.FullName, baseMethod.Name);
            }

            var delegateProxy = (DelegateProxyAttribute)delegateProxies [0];

            if (delegateProxy.DelegateType == null)
            {
                throw ErrorHelper.CreateError(8012, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: DelegateType is null. Please file a bug at http://bugzilla.xamarin.com.", baseMethod.DeclaringType.FullName, baseMethod.Name);
            }

            var delegateProxyField = delegateProxy.DelegateType.GetField("Handler", BindingFlags.NonPublic | BindingFlags.Static);

            if (delegateProxyField == null)
            {
                throw ErrorHelper.CreateError(8013, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: DelegateType ({2}) specifies a type without a 'Handler' field. Please file a bug at http://bugzilla.xamarin.com.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxy.DelegateType.FullName);
            }

            var handlerDelegate = delegateProxyField.GetValue(null);

            if (handlerDelegate == null)
            {
                throw ErrorHelper.CreateError(8014, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: The DelegateType's ({2}) 'Handler' field is null. Please file a bug at http://bugzilla.xamarin.com.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxy.DelegateType.FullName);
            }

            if (!(handlerDelegate is Delegate))
            {
                throw ErrorHelper.CreateError(8015, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: The DelegateType's ({2}) 'Handler' field is not a delegate, it's a {3}. Please file a bug at http://bugzilla.xamarin.com.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxy.DelegateType.FullName, handlerDelegate.GetType().FullName);
            }

            // We now have the information we need to create the block.
            // Note that we must create a heap-allocated block, so we
            // start off by creating a stack-allocated block, and then
            // call _Block_copy, which will create a heap-allocated block
            // with the proper reference count.
            BlockLiteral block = new BlockLiteral();

            if (signature == null)
            {
                if (Runtime.DynamicRegistrationSupported)
                {
                    block.SetupBlock((Delegate)handlerDelegate, (Delegate)@delegate);
                }
                else
                {
                    throw ErrorHelper.CreateError(8026, $"BlockLiteral.GetBlockForDelegate with a null signature is not supported when the dynamic registrar has been linked away (delegate type: {@delegate.GetType ().FullName}).");
                }
            }
            else
            {
                block.SetupBlockImpl((Delegate)handlerDelegate, (Delegate)@delegate, true, signature);
            }
            var rv = _Block_copy(ref block);

            block.CleanupBlock();
            return(rv);
        }