예제 #1
0
        /// <summary>
        /// Return the unmanaged C++ pointer from a <see cref="ICallbackable"/> instance.
        /// </summary>
        /// <typeparam name="TCallback">The type of the callback.</typeparam>
        /// <param name="callback">The callback.</param>
        /// <returns>A pointer to the unmanaged C++ object of the callback</returns>
        public static IntPtr ToCallbackPtr <TCallback>(ICallbackable callback)
            where TCallback : ICallbackable
        {
            // If callback is null, then return a null pointer
            if (callback == null)
            {
                return(IntPtr.Zero);
            }

            // If callback is CppObject
            if (callback is CppObject)
            {
                return(((CppObject)callback).NativePointer);
            }

            // Setup the shadow container in order to support multiple inheritance
            var shadowContainer = callback.Shadow as ShadowContainer;

            if (shadowContainer == null)
            {
                shadowContainer = new ShadowContainer();
                shadowContainer.Initialize(callback);
            }

            return(shadowContainer.Find(typeof(TCallback)));
        }
예제 #2
0
        public static IntPtr ToIntPtr <TCallback>(ICallbackable callback) where TCallback : ICallbackable
        {
            if (callback == null)
            {
                return(IntPtr.Zero);
            }
            if (callback is CppObject)
            {
                return(((CppObject)callback).NativePointer);
            }
            ShadowContainer shadowContainer = callback.Shadow as ShadowContainer;

            if (shadowContainer == null)
            {
                shadowContainer = new ShadowContainer();
                shadowContainer.Initialize(callback);
            }
            return(shadowContainer.Find(typeof(TCallback)));
        }