CPF/CPF.Mac/Mac/Foundation/InternalNSNotificationHandler.cs
2023-11-21 23:05:03 +08:00

37 lines
760 B
C#

using System;
namespace CPF.Mac.Foundation
{
[Register]
internal class InternalNSNotificationHandler : NSObject
{
private NSNotificationCenter notificationCenter;
private Action<NSNotification> notify;
public InternalNSNotificationHandler(NSNotificationCenter notificationCenter, Action<NSNotification> notify)
{
this.notificationCenter = notificationCenter;
this.notify = notify;
}
[Export("post:")]
[Preserve(Conditional = true)]
public void Post(NSNotification s)
{
notify(s);
s.Dispose();
}
protected override void Dispose(bool disposing)
{
if (disposing && notificationCenter != null)
{
notificationCenter.RemoveObserver(this);
notificationCenter = null;
}
base.Dispose(disposing);
}
}
}