Subscription.cs 666 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho
  4. {
  5. public class Subscription {
  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 Unsubscribe ()
  16. {
  17. Runtime.Validate(typeof(Subscription));
  18. if (UnmanagedProxy == IntPtr.Zero)
  19. return;
  20. urho_unsubscribe (UnmanagedProxy);
  21. UnmanagedProxy = IntPtr.Zero;
  22. gch.Free ();
  23. }
  24. }
  25. }