Ejemplo n.º 1
0
 public void Listen(Action <TParam1> listener)
 {
     Assert.That(!_listeners.Contains(listener),
                 () => "Tried to add method '{0}' to signal '{1}' but it has already been added"
                 .Fmt(SignalInternalUtil.MethodToString(listener.Method), this.GetType().Name));
     _listeners.Add(listener);
 }
Ejemplo n.º 2
0
        public void Unlisten(Action <TParam1> listener)
        {
            bool success = _listeners.Remove(listener);

            Assert.That(success,
                        () => "Tried to remove method '{0}' from signal '{1}' without adding it first"
                        .Fmt(SignalInternalUtil.MethodToString(listener.Method), this.GetType().Name));
        }
Ejemplo n.º 3
0
        void IDisposable.Dispose()
        {
            Assert.That(!_hasDisposed, "Tried to dispose signal '{0}' twice", this.GetType().Name);
            _hasDisposed = true;

            // If you don't want to verify that all event handlers have been removed feel free to comment out this assert or remove
            Assert.That(_listeners.IsEmpty(),
                        () => "Found {0} methods still added to signal '{1}'.  Methods: {2}"
                        .Fmt(_listeners.Count, this.GetType().Name, _listeners.Select(x => SignalInternalUtil.MethodToString(x.Method)).Join(", ")));
        }