public ObjectPropertyCollection(IObjectInstance objectInstance, ClassProperty classProperty, bool hasChildObjects) : base(objectInstance, classProperty) { _hasChildObjects = hasChildObjects; if (ClassProperty.CanRead) { // Bind to the observable collection. ClassProperty.SetUserOutput(ObjectInstance, _collection); // When the collection is out of date, update it from the wrapped object. _depCollection = new Computed(OnUpdateCollection); } }
public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty, bool hasChildObject) : base(objectInstance, classProperty) { _hasChildObject = hasChildObject; if (ClassProperty.CanRead) { // When the property is out of date, update it from the wrapped object. _depProperty = new Computed(delegate { object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject); if (_hasChildObject) { IObjectInstance oldChild = _child; object oldValue = oldChild == null ? null : oldChild.WrappedObject; _child = null; IObjectInstance wrapper; if (value == null) { wrapper = null; } else if (value == oldValue) { wrapper = oldChild; _child = wrapper; } else { if (WrapObject(value, out wrapper)) { _child = wrapper; } } ClassProperty.SetUserOutput(ObjectInstance, wrapper); if (oldChild != _child && oldChild != null) { ObjectInstance.Tree.RemoveKey(oldValue); oldChild.Dispose(); } } else { ClassProperty.SetUserOutput(ObjectInstance, value); } }); } }