Example #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);
                    }
                }
            }
        }
        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;
                    }
                }
            }
        }