static void InvokeNativeCompletionBlock(IntPtr block, int value) { unsafe { var literal = (BlockLiteral *)block; var copy = LibObjc._Block_copy(block); var invoker = literal->GetDelegateForBlock <NativeCompletionHandlerDelegate>(); invoker(copy, value); LibObjc._Block_release(copy); } }
protected TDelegate dlg; // Your delegate public Swizzle(Class victim, IntPtr selector, TDelegate del, bool isClassMethod = false) { dlg = del; victimSel = selector; originalMethod = isClassMethod ? LibObjc.class_getClassMethod(victim.Handle, victimSel) : LibObjc.class_getInstanceMethod(victim.Handle, victimSel); originalImpl = LibObjc.method_getImplementation(originalMethod); newImpl = Marshal.GetFunctionPointerForDelegate(del as System.Delegate); LibObjc.method_setImplementation(originalMethod, newImpl); }
protected TDelegate dlg; // Your delegate public Swizzle(NSObject victim, string selector, TDelegate del) { dlg = del; victimSel = Selector.GetHandle(selector); originalMethod = LibObjc.class_getInstanceMethod(victim.ClassHandle, victimSel); originalImpl = LibObjc.method_getImplementation(originalMethod); newImpl = Marshal.GetFunctionPointerForDelegate(del as System.Delegate); LibObjc.method_setImplementation(originalMethod, newImpl); }
protected virtual void Dispose(bool disposing) { if (isDisposed) { return; } if (originalMethod != IntPtr.Zero && originalImpl != IntPtr.Zero) { LibObjc.method_setImplementation(originalMethod, originalImpl); originalMethod = IntPtr.Zero; } isDisposed = true; }
public virtual void Schedule(ScheduleBlock block) { if (block == null) { throw new ArgumentNullException(nameof(block)); } var blocklit = new BlockLiteral(); blocklit.SetupBlock(scheduleBlockProxy, block); try { unsafe { var blockref = &blocklit; LibObjc.void_objc_msgSend_IntPtr(this.Handle, selScheduleWithBlock, (IntPtr)blockref); } } finally { blocklit.CleanupBlock(); } }
public void Dispose() { LibObjc.method_setImplementation(swizzle.originalMethod, swizzle.newImpl); swizzle = null; }
public Unswizzle(Swizzle <TDelegate> swizzle) { this.swizzle = swizzle; LibObjc.method_setImplementation(swizzle.originalMethod, swizzle.originalImpl); }
internal static IntPtr New(Type type) { return(LibObjc.IntPtr_objc_msgSend(Class.GetHandle(type), Selector.GetHandle("new"))); }
public virtual void Invalidate() { LibObjc.void_objc_msgSend(Handle, selInvalidate); }
public NSBackgroundActivityScheduler(string identifier) : base(LibObjc.IntPtr_objc_msgSend_IntPtr( Class.GetHandle(className), selAlloc, new NSString(identifier).Handle)) { LibObjc.void_objc_msgSend_IntPtr(Handle, selInitWithIdentifier, new NSString(identifier).Handle); }
unsafe void SetupHandler(BlockLiteral *block_ptr_handler) { LibObjc.IntPtr_objc_msgSend_IntPtr(Handle, selScheduleWithBlock.Handle, new IntPtr(block_ptr_handler)); }
public virtual void Dispose() { LibObjc.method_setImplementation(originalMethod, originalImpl); }