/// <summary> /// Attaches the specified properties container as nested properties. /// /// This method is intended to be used in conjunction with the <see cref="IMementoCapable"/> pattern /// where a new unattached properties container is created and then later attached to a parent container. /// </summary> public void SetNestedProperties(string key, Properties properties) { if (properties == null) { Remove(key); return; } lock (syncRoot) { for (Properties ancestor = this; ancestor != null; ancestor = ancestor.parent) { if (ancestor == properties) throw new InvalidOperationException("Cannot add a properties container to itself."); } object oldValue; if (dict.TryGetValue(key, out oldValue)) { if (oldValue == properties) return; HandleOldValue(oldValue); } lock (properties.syncRoot) { if (properties.parent != null) throw new InvalidOperationException("Cannot attach nested properties that already have a parent."); MakeDirty(); properties.SetSyncRoot(syncRoot); properties.parent = this; dict[key] = properties; } } OnPropertyChanged(key); }