Ejemplo n.º 1
0
        //[OnDeserialized]
        //private void OnDeserialized(StreamingContext context)
        //{
        //    RebindEvents();
        //}

        protected virtual void ChildCollectionChanged(object?sender, NotifyCollectionChangedEventArgs args)
        {
            string?propertyName = AttributeManager <NotifyCollectionChangedAttribute> .FindPropertyName(this, sender !);

            if (propertyName != null)
            {
                NotifyPrivate(propertyName);
            }

            if (AttributeManager <NotifyChildPropertyAttribute> .FieldsWithAttribute(this).Contains(sender))
            {
                if (args.NewItems != null)
                {
                    foreach (var p in args.NewItems.Cast <ModifiableEntity>())
                    {
                        p.SetParentEntity(this);
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (var p in args.OldItems.Cast <ModifiableEntity>())
                    {
                        p.SetParentEntity(this);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual void RebindEvents()
        {
            foreach (INotifyCollectionChanged notify in AttributeManager <NotifyCollectionChangedAttribute> .FieldsWithAttribute(this))
            {
                if (notify == null)
                {
                    continue;
                }

                notify.CollectionChanged += ChildCollectionChanged;
            }

            foreach (object field in AttributeManager <NotifyChildPropertyAttribute> .FieldsWithAttribute(this))
            {
                if (field == null)
                {
                    continue;
                }

                var entity = field as ModifiableEntity;
                if (entity != null)
                {
                    entity.SetParentEntity(this);
                }
                else
                {
                    foreach (ModifiableEntity item in (IEnumerable)field)
                    {
                        item.SetParentEntity(this);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected virtual void RebindEvents()
        {
            foreach (INotifyCollectionChanged?notify in AttributeManager <NotifyCollectionChangedAttribute> .FieldsWithAttribute(this))
            {
                if (notify == null)
                {
                    continue;
                }

                notify.CollectionChanged += ChildCollectionChanged;
            }

            foreach (object?field in AttributeManager <NotifyChildPropertyAttribute> .FieldsWithAttribute(this))
            {
                if (field == null)
                {
                    continue;
                }

                if (field is ModifiableEntity entity)
                {
                    entity.SetParentEntity(this);
                }
                else
                {
                    foreach (var item in (IEnumerable <IModifiableEntity>)field !)
                    {
                        ((ModifiableEntity)item).SetParentEntity(this);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected virtual void ChildCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            string propertyName = AttributeManager <NotifyCollectionChangedAttribute> .FindPropertyName(this, sender);

            if (propertyName != null)
            {
                NotifyPrivate(propertyName);
            }

            if (AttributeManager <NotifyChildPropertyAttribute> .FieldsWithAttribute(this).Contains(sender))
            {
                if (args.NewItems != null)
                {
                    foreach (var p in args.NewItems.Cast <INotifyPropertyChanged>())
                    {
                        p.PropertyChanged += ChildPropertyChanged;
                    }
                }
                if (args.OldItems != null)
                {
                    foreach (var p in args.OldItems.Cast <INotifyPropertyChanged>())
                    {
                        p.PropertyChanged -= ChildPropertyChanged;
                    }
                }
            }

            if (AttributeManager <ValidateChildPropertyAttribute> .FieldsWithAttribute(this).Contains(sender))
            {
                if (args.NewItems != null)
                {
                    foreach (var p in args.NewItems.Cast <ModifiableEntity>())
                    {
                        p.ExternalPropertyValidation += ChildPropertyValidation;
                    }
                }
                if (args.OldItems != null)
                {
                    foreach (var p in args.OldItems.Cast <ModifiableEntity>())
                    {
                        p.ExternalPropertyValidation -= ChildPropertyValidation;
                    }
                }
            }
        }