/// <summary> /// Add an observer when the key changes on the key path. /// All objects in the path *MUST* inherit from KVCObject for the path to be followed. /// </summary> /// <param name="keyPath">A Period seprated list of Key values</param> /// <param name="observer"></param> public void addObserverForKeyPath(string keyPath, observeValueForKey observer) { //Get our Key and the rest of the keyPath string[] keys = keyPath.Split(".".ToCharArray(), 2); //Did we get 2 keys? if (keys.Length == 2) { //Get the Key value, then call it's addObserverForKeyPath object val = valueForKey(keys[0]); if (val is KVCObject) //Verifiy it's the right type { ((KVCObject)val).addObserverForKeyPath(keys[1], observer); } else { //Not a DBObject, just do a normal add addObserverForKey(keys[0], observer); } } else { //It's just a normal key addObserverForKey(keys[0], observer); } }
/// <summary> /// Add an observer for when the Key changes. /// </summary> /// <param name="key">The key you want to watch</param> /// <param name="observer">delegate observeValueForKey</param> public void addObserverForKey(string key, observeValueForKey observer) { if (!_kvo.ContainsKey(key)) { _kvo.Add(key, observer); } else { //Add the observer _kvo[key] += observer; } }
/// <summary> /// Remove an observer from the Key changes. /// </summary> /// <param name="key"></param> /// <param name="observer"></param> public void removeObserverForKey(string key, observeValueForKey observer) { if (_kvo.ContainsKey(key)) { _kvo[key] -= observer; } }