Esempio n. 1
0
 public override void Dispose()
 {
     if (_child != null)
     {
         ObjectInstance.Tree.RemoveKey(_child.WrappedObject);
         _child.Dispose();
     }
     using (NotificationGate.BeginOutbound())
     {
         ObjectInstance.ClearValue(ClassProperty.DependencyProperty);
     }
     _depProperty.Dispose();
 }
Esempio n. 2
0
        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);
                    }
                });
            }
        }