/// <summary> /// Converts an <see cref="ICallbackable"/> array to an array of native object pointers. /// </summary> public static void ConvertToPointerArray <TCallback>(Span <IntPtr> pointers, ReadOnlySpan <TCallback> interfaces) where TCallback : ICallbackable { var arrayLength = interfaces.Length; Guid?callbackTypeGuid = null; for (var i = 0; i < arrayLength; ++i) { pointers[i] = interfaces[i] switch { null => IntPtr.Zero, CppObject cpp => cpp.NativePointer, { } item => item.Shadow.Find(callbackTypeGuid ??= GetCallbackTypeGuid()) } } ;
/// <summary> /// Return the unmanaged C++ pointer from a <see cref="CppObject"/> instance. /// </summary> /// <typeparam name="TCallback">The type of the callback.</typeparam> /// <param name="obj">The object.</param> /// <returns>A pointer to the unmanaged C++ object of the callback</returns> /// <remarks>This method is meant as a fast-path for codegen to use to reduce the number of casts.</remarks> public static IntPtr ToCallbackPtr <TCallback>(CppObject obj) where TCallback : ICallbackable => obj?.NativePointer ?? IntPtr.Zero;
/// <summary> /// Initializes this instance with a pointer from a temporary object and set the pointer of the temporary /// object to IntPtr.Zero. /// </summary> /// <param name="temp">The instance to get the NativePointer.</param> protected void FromTemp(CppObject temp) { NativePointer = temp.NativePointer; temp.NativePointer = IntPtr.Zero; }