Subscription.cs 735 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho
  4. {
  5. public class Subscription : IDisposable {
  6. internal GCHandle gch;
  7. internal IntPtr UnmanagedProxy;
  8. internal Subscription (Action<IntPtr> proxy)
  9. {
  10. Runtime.Validate(typeof(Subscription));
  11. gch = GCHandle.Alloc (proxy);
  12. }
  13. [DllImport (Consts.NativeImport, CallingConvention=CallingConvention.Cdecl)]
  14. extern static void urho_unsubscribe (IntPtr notificationProxy);
  15. public void Dispose()
  16. {
  17. Unsubscribe ();
  18. }
  19. public void Unsubscribe ()
  20. {
  21. Runtime.Validate(typeof(Subscription));
  22. if (UnmanagedProxy == IntPtr.Zero)
  23. return;
  24. urho_unsubscribe (UnmanagedProxy);
  25. UnmanagedProxy = IntPtr.Zero;
  26. gch.Free ();
  27. }
  28. }
  29. }