/// <summary> /// Register the given observer /// </summary> public void Attach(IFieldsObserver observer) { if (observer == null) { return; } List <IFieldsObserver> observers; if (!_fieldsObservers.TryGetValue(observer.EntityType, out observers)) { observers = new List <IFieldsObserver>(); _fieldsObservers[observer.EntityType] = observers; } // since we are using the same window for displaying var existingObserver = observers.FirstOrDefault(o => o.Id == observer.Id); if (existingObserver != null) { observers.Remove(existingObserver); } observers.Add(observer); }
/// <summary> /// Unregister the given observer /// </summary> public void Detach(IFieldsObserver observer) { if (observer == null) { return; } List <IFieldsObserver> observers; if (!_fieldsObservers.TryGetValue(observer.EntityType, out observers)) { return; } observers.Remove(observer); if (observers.Count == 0) { _fieldsObservers.Remove(observer.EntityType); } }