Skip to content

Commit

Permalink
[NUI] Add non-generic WeakEventProxy
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor authored and tscholb committed Aug 1, 2023
1 parent 4638186 commit 0a185b1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Tizen.NUI/src/internal/Common/WeakEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,39 @@ private void OnEventInvoked(object sender, EventArgsT args)
Invoke(sender, args as EventArgs);
}
}

/// <summary>
/// The non-generic version of <see cref="WeakEventProxy"/>.
/// </summary>
internal abstract class WeakEventProxy : WeakEvent<EventHandler>
{
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);
}
}
}

0 comments on commit 0a185b1

Please sign in to comment.