using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Uestc.Auto6.Dso.Core { public abstract class Collection { public string ID; public Collection(string id, IBroadcaster pub) { ID = id; if (pub != null) pub.PublisherChanged += HandleCustomEvent; } public abstract void HandleCustomEvent(object? sender, CustomEventArg e); public void Add(IBroadcaster pub) { pub.PublisherChanged += HandleCustomEvent; } public void Remove(IBroadcaster pub) { try { pub.PublisherChanged -= HandleCustomEvent; } catch (Exception) { } } public event EventHandler? ExternalEvents; public void Add(IBroadcaster pub, EventHandler e) { pub.PublisherChanged += HandleCustomEvent; ExternalEvents += e; } public void Remove(IBroadcaster pub, EventHandler e) { try { pub.PublisherChanged -= HandleCustomEvent; ExternalEvents -= e; } catch (Exception) { } } } }