using System; namespace Svelto.Observer.InterNamespace { public abstract class Observer : IObserver { protected Observer(Observable observable) { observable.Notify += OnObservableDispatched; _unsubscribe = () => observable.Notify -= OnObservableDispatched; } public void AddAction(ObserverAction action) { _actions += action; } public void RemoveAction(ObserverAction action) { _actions -= action; } public void Unsubscribe() { _unsubscribe(); } void OnObservableDispatched(ref DispatchType dispatchNotification) { if (_actions != null) { var actionType = TypeMap(ref dispatchNotification); _actions(ref actionType); } } protected abstract ActionType TypeMap(ref DispatchType dispatchNotification); ObserverAction _actions; Action _unsubscribe; } } namespace Svelto.Observer.IntraNamespace { public class Observer : InterNamespace.Observer { public Observer(Observable observable) : base(observable) { } protected override DispatchType TypeMap(ref DispatchType dispatchNotification) { return dispatchNotification; } } } namespace Svelto.Observer { public class Observer: IObserver { public Observer(Observable observable) { observable.Notify += OnObservableDispatched; _unsubscribe = () => observable.Notify -= OnObservableDispatched; } public void AddAction(Action action) { _actions += action; } public void RemoveAction(Action action) { _actions -= action; } public void Unsubscribe() { _unsubscribe(); } void OnObservableDispatched() { if (_actions != null) _actions(); } Action _actions; readonly Action _unsubscribe; } public interface IObserver { void AddAction(ObserverAction action); void RemoveAction(ObserverAction action); void Unsubscribe(); } public interface IObserver { void AddAction(Action action); void RemoveAction(Action action); void Unsubscribe(); } }