private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback) { Action <IntPtr> callback2 = delegate(IntPtr result) { NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(result); if (callback != null) { callback(nativeRealTimeRoom); } else { nativeRealTimeRoom?.Dispose(); } }; return(Callbacks.ToIntPtr(callback2)); }
// This is a workaround to the fact that we're lacking proper copy constructors on the cwrapper // structs. Clients of the RealTimeEventListener need to hold long-lived references to the // room returned by the callback, but the default implementation of the utility callback method // cleans up all arguments to the callback. This can be gotten rid of when copy constructors // are present in the native sdk. private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback) { Action <IntPtr> pointerReceiver = result => { NativeRealTimeRoom converted = NativeRealTimeRoom.FromPointer(result); if (callback != null) { callback(converted); } else { if (converted != null) { converted.Dispose(); } } }; return(Callbacks.ToIntPtr(pointerReceiver)); }
private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback) { return(Callbacks.ToIntPtr((Delegate)(result => { NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(result); if (callback != null) { callback(nativeRealTimeRoom); } else { if (nativeRealTimeRoom == null) { return; } nativeRealTimeRoom.Dispose(); } }))); }