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); }