From 0a185b156588c93ffcb5da53e9990d876f2e688e Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Tue, 1 Aug 2023 14:05:55 +0900 Subject: [PATCH] [NUI] Add non-generic WeakEventProxy Signed-off-by: Jiyun Yang --- .../src/internal/Common/WeakEvent.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Tizen.NUI/src/internal/Common/WeakEvent.cs b/src/Tizen.NUI/src/internal/Common/WeakEvent.cs index a2745cf5500..e886b935e7c 100755 --- a/src/Tizen.NUI/src/internal/Common/WeakEvent.cs +++ b/src/Tizen.NUI/src/internal/Common/WeakEvent.cs @@ -130,4 +130,39 @@ private void OnEventInvoked(object sender, EventArgsT args) Invoke(sender, args as EventArgs); } } + + /// + /// The non-generic version of . + /// + internal abstract class WeakEventProxy : WeakEvent + { + protected abstract void ConnectToEvent(EventHandler handler); + + protected abstract void DisconnectToEvent(EventHandler handler); + + public override void Add(EventHandler handler) + { + if (Count == 0) + { + ConnectToEvent(OnEventInvoked); + } + + base.Add(handler); + } + + public override void Remove(EventHandler handler) + { + base.Remove(handler); + + if (Count == 0) + { + DisconnectToEvent(OnEventInvoked); + } + } + + private void OnEventInvoked(object sender, EventArgs args) + { + Invoke(sender, args); + } + } }