Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     LibObjc.method_setImplementation(swizzle.originalMethod, swizzle.newImpl);
     swizzle = null;
 }
Ejemplo n.º 5
0
 public Unswizzle(Swizzle <TDelegate> swizzle)
 {
     this.swizzle = swizzle;
     LibObjc.method_setImplementation(swizzle.originalMethod, swizzle.originalImpl);
 }
Ejemplo n.º 6
0
 public virtual void Dispose()
 {
     LibObjc.method_setImplementation(originalMethod, originalImpl);
 }