internal CTRunDelegateCallbacks GetCallbacks() { var callbacks = new CTRunDelegateCallbacks() { version = CTRunDelegateVersion.Version1, dealloc = Deallocate, }; var flags = BindingFlags.Public | BindingFlags.Instance; MethodInfo m; if ((m = this.GetType().GetMethod("GetAscent", flags)) != null && m.DeclaringType != typeof(CTRunDelegateOperations)) { callbacks.getAscent = GetAscent; } if ((m = this.GetType().GetMethod("GetDescent", flags)) != null && m.DeclaringType != typeof(CTRunDelegateOperations)) { callbacks.getDescent = GetDescent; } if ((m = this.GetType().GetMethod("GetWidth", flags)) != null && m.DeclaringType != typeof(CTRunDelegateOperations)) { callbacks.getWidth = GetWidth; } return(callbacks); }
static IntPtr Create(CTRunDelegateOperations operations) { if (operations == null) { throw new ArgumentNullException(nameof(operations)); } CTRunDelegateCallbacks callbacks = operations.GetCallbacks(); return(CTRunDelegateCreate(ref callbacks, operations.Handle)); }
internal CTRunDelegateCallbacks GetCallbacks() { var callbacks = new CTRunDelegateCallbacks() { version = 1, // kCTRunDelegateVersion1 dealloc = Deallocate, getAscent = GetAscent, getDescent = GetDescent, getWidth = GetWidth, }; return(callbacks); }
CTRunDelegateCallbacks callbacks; // prevent GC since they are called from native code public CTRunDelegate(CTRunDelegateOperations operations) { if (operations == null) { throw ConstructorError.ArgumentNull(this, "operations"); } callbacks = operations.GetCallbacks(); handle = CTRunDelegateCreate(callbacks, GCHandle.ToIntPtr(operations.handle)); if (handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
static extern IntPtr CTRunDelegateCreate(ref CTRunDelegateCallbacks callbacks, IntPtr refCon);