示例#1
0
        public IPropertyInfo GetMethodHandle(INotifyPropertyChangedSource obj, String propertyName)
        {
            IPropertyInfo property = PropertyInfoProvider.GetProperty(obj, propertyName);

            if (property != null)
            {
                return(property);
            }
            throw new Exception("Property not found: " + obj.GetType().FullName + "." + propertyName);
        }
示例#2
0
        public void FirePropertyChange(INotifyPropertyChangedSource obj, PropertyChangeSupport propertyChangeSupport, IPropertyInfo property, Object oldValue, Object currentValue)
        {
            ICacheModification cacheModification = this.CacheModification;
            PropertyEntry      entry             = GetPropertyEntry(obj.GetType(), property);

            if (currentValue == null)
            {
                currentValue = entry.getDelegate(obj);
            }
            try
            {
                if (entry.isAddedRemovedCheckNecessary)
                {
                    if (oldValue != null)
                    {
                        HandleRemovedItem(obj, oldValue, entry.isParentChildSetter);
                    }
                    if (currentValue != null)
                    {
                        HandleAddedItem(obj, currentValue, entry.isParentChildSetter);
                    }
                }
                String[] propertyNames = entry.propertyNames;
                Object[] oldValues;
                Object[] currentValues;

                if (FireOldPropertyValueActive)
                {
                    oldValues     = CreateArrayOfValues(oldValue, propertyNames.Length);
                    currentValues = Object.ReferenceEquals(currentValue, oldValue) ? oldValues : CreateArrayOfValues(currentValue, propertyNames.Length);
                }
                else
                {
                    oldValues     = entry.unknownValues;
                    currentValues = oldValues;
                }
                FirePropertyChange(obj, entry.pceArgs, propertyNames, oldValues, currentValues);
                if (entry.firesToBeCreatedPCE)
                {
                    IDataObject dObj = (IDataObject)obj;
                    if (dObj.ToBeCreated && dObj.ToBeUpdated)
                    {
                        dObj.ToBeUpdated = false;
                    }
                }
            }
            finally
            {
                if (entry.doesModifyToBeUpdated && !cacheModification.ActiveOrFlushingOrInternalUpdate)
                {
                    SetToBeUpdated(obj, true);
                }
            }
        }
示例#3
0
        public void HandleCollectionChange(INotifyPropertyChangedSource obj, Object sender, NotifyCollectionChangedEventArgs evnt)
        {
            IEntityMetaData metaData = ((IEntityMetaDataHolder)obj).Get__EntityMetaData();

            Object bases = null;
            bool   parentChildProperty = false;

            RelationMember[] relationMembers = metaData.RelationMembers;
            for (int relationIndex = relationMembers.Length; relationIndex-- > 0;)
            {
                Object valueDirect = ((IValueHolderContainer)obj).Get__ValueDirect(relationIndex);
                if (!Object.ReferenceEquals(valueDirect, sender))
                {
                    continue;
                }
                if (relationMembers[relationIndex].GetAnnotation(typeof(ParentChild)) != null)
                {
                    bases = obj;
                    parentChildProperty = true;
                }
                else
                {
                    bases = sender;
                }
                break;
            }
            if (bases == null)
            {
                foreach (PrimitiveMember primitiveMember in metaData.PrimitiveMembers)
                {
                    Object valueDirect = primitiveMember.GetValue(obj);
                    if (!Object.ReferenceEquals(valueDirect, sender))
                    {
                        continue;
                    }
                    bases = obj;
                    parentChildProperty = true;
                    break;
                }
            }
            if (bases == null)
            {
                throw new Exception("Must never happen");
            }
            ICacheModification cacheModification = this.CacheModification;
            bool oldCacheModification            = cacheModification.Active;
            bool cacheModificationUsed           = false;

            try
            {
                switch (evnt.Action)
                {
                case NotifyCollectionChangedAction.Add:
                case NotifyCollectionChangedAction.Remove:
                case NotifyCollectionChangedAction.Replace:
                    if (evnt.OldItems != null)
                    {
                        foreach (Object oldItem in evnt.OldItems)
                        {
                            HandleRemovedItem(obj, oldItem, parentChildProperty);
                        }
                    }
                    if (evnt.NewItems != null)
                    {
                        foreach (Object newItem in evnt.NewItems)
                        {
                            HandleAddedItem(obj, newItem, parentChildProperty);
                        }
                    }
                    break;

#if !SILVERLIGHT
                case NotifyCollectionChangedAction.Move:
                    // Nothing to do in that case
                    break;
#endif
                case NotifyCollectionChangedAction.Reset:
                    throw new NotSupportedException("Reset is not allowed in a managed collection");

                default:
                    throw RuntimeExceptionUtil.CreateEnumNotSupportedException(evnt.Action);
                }
                IList <ICollectionChangeExtension> extensions = collectionChangeExtensions.GetExtensions(obj.GetType());
                for (int a = 0, size = extensions.Count; a < size; a++)
                {
                    extensions[a].CollectionChanged(obj, evnt);
                }
            }
            finally
            {
                if (!oldCacheModification)
                {
                    SetToBeUpdated(obj, true);
                }
                if (cacheModificationUsed)
                {
                    cacheModification.Active = oldCacheModification;
                }
            }
        }
示例#4
0
        public void FirePropertyChange(INotifyPropertyChangedSource obj, PropertyChangedEventArgs[] evnts, String[] propertyNames, Object[] oldValues, Object[] currentValues)
        {
            PropertyChangeSupport            propertyChangeSupport = obj.PropertyChangeSupport;
            IList <IPropertyChangeExtension> extensions            = propertyChangeExtensions.GetExtensions(obj.GetType());

            if (propertyChangeSupport == null && extensions == null && !(obj is IPropertyChangedEventHandler))
            {
                return;
            }
            ICacheModification cacheModification = this.CacheModification;

            if (cacheModification.Active)
            {
                cacheModification.QueuePropertyChangeEvent(delegate()
                {
                    ExecuteFirePropertyChange(propertyChangeSupport, extensions, obj, evnts, propertyNames, oldValues, currentValues);
                });
                return;
            }
            ExecuteFirePropertyChange(propertyChangeSupport, extensions, obj, evnts, propertyNames, oldValues, currentValues);
        }