예제 #1
0
 protected virtual string ChildPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
 {
     return(null);
 }
예제 #2
0
 public IntegrityCheckWithEntity(IntegrityCheck integrityCheck, ModifiableEntity entity)
 {
     this.IntegrityCheck = integrityCheck;
     this.Entity         = entity;
 }
예제 #3
0
        public bool?MatchesEntity(ModifiableEntity entity)
        {
            if (this.Type != entity.GetType())
            {
                return(false);
            }

            if (this.PropertyRouteType == PropertyRouteType.Root)
            {
                return(true);
            }


            switch (this.PropertyRouteType)
            {
            case PropertyRouteType.Root: return(true);

            case PropertyRouteType.FieldOrProperty:
            {
                var parentEntity = entity.GetParentEntity();

                if (parentEntity == null)
                {
                    return(null);
                }

                var result = this.Parent.MatchesEntity(parentEntity);
                if (result != true)
                {
                    return(result);
                }

                return(this.PropertyInfo.GetValue(parentEntity) == entity);
            }

            case PropertyRouteType.Mixin:
            {
                var mixin      = (MixinEntity)entity;
                var mainEntity = mixin.MainEntity;

                var result = this.Parent.MatchesEntity(mainEntity);
                if (result != true)
                {
                    return(result);
                }

                return(mainEntity.Mixins.Contains(mixin));
            }

            case PropertyRouteType.MListItems:
            {
                var parentEntity = entity.GetParentEntity();

                if (parentEntity == null)
                {
                    return(null);
                }

                var result = this.Parent.Parent.MatchesEntity(parentEntity);
                if (result != true)
                {
                    return(result);
                }

                var list = (IList)this.PropertyInfo.GetValue(parentEntity);

                return(list != null && list.Contains(entity));
            }

            case PropertyRouteType.LiteEntity:
            default:
                throw new NotImplementedException();
            }
        }
예제 #4
0
 public object?GetValueUntyped(ModifiableEntity entity)
 {
     return(GetValue((T)entity));
 }
예제 #5
0
 public string?PropertyCheck(ModifiableEntity modifiableEntity)
 {
     return(PropertyCheck((T)modifiableEntity));
 }
예제 #6
0
 protected MixinEntity(ModifiableEntity mainEntity, MixinEntity?next)
 {
     this.mainEntity = mainEntity;
     this.next       = next;
 }
        protected virtual bool Set <T>(ref T field, T value, [CallerMemberNameAttribute] string automaticPropertyName = null)
        {
            if (EqualityComparer <T> .Default.Equals(field, value))
            {
                return(false);
            }

            PropertyInfo pi = GetPropertyInfo(automaticPropertyName);

            if (pi == null)
            {
                throw new ArgumentException("No PropertyInfo with name {0} found in {1} or any implemented interface".FormatWith(automaticPropertyName, this.GetType().TypeName()));
            }

            if (value is IMListPrivate && !((IMListPrivate)value).IsNew && !object.ReferenceEquals(value, field))
            {
                throw new InvalidOperationException("Only MList<T> with IsNew = true can be assigned to an entity");
            }

            INotifyCollectionChanged col = field as INotifyCollectionChanged;

            if (col != null)
            {
                if (AttributeManager <NotifyCollectionChangedAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    col.CollectionChanged -= ChildCollectionChanged;
                }

                if (AttributeManager <NotifyChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    foreach (INotifyPropertyChanged item in (IEnumerable)col)
                    {
                        item.PropertyChanged -= ChildPropertyChanged;
                    }
                }

                if (AttributeManager <ValidateChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    foreach (ModifiableEntity item in (IEnumerable)col)
                    {
                        item.ExternalPropertyValidation -= ChildPropertyValidation;
                    }
                }
            }

            ModifiableEntity mod = field as ModifiableEntity;

            if (mod != null)
            {
                if (AttributeManager <NotifyChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    mod.PropertyChanged -= ChildPropertyChanged;
                }

                if (AttributeManager <ValidateChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    mod.ExternalPropertyValidation -= ChildPropertyValidation;
                }
            }

            SetSelfModified();
            field = value;

            col = field as INotifyCollectionChanged;
            if (col != null)
            {
                if (AttributeManager <NotifyCollectionChangedAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    col.CollectionChanged += ChildCollectionChanged;
                }

                if (AttributeManager <NotifyChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    foreach (INotifyPropertyChanged item in (IEnumerable)col)
                    {
                        item.PropertyChanged += ChildPropertyChanged;
                    }
                }

                if (AttributeManager <ValidateChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    foreach (ModifiableEntity item in (IEnumerable)col)
                    {
                        item.ExternalPropertyValidation += ChildPropertyValidation;
                    }
                }
            }

            mod = field as ModifiableEntity;
            if (mod != null)
            {
                if (AttributeManager <NotifyChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    mod.PropertyChanged += ChildPropertyChanged;
                }

                if (AttributeManager <ValidateChildPropertyAttribute> .FieldContainsAttribute(GetType(), pi))
                {
                    mod.ExternalPropertyValidation += ChildPropertyValidation;
                }
            }

            NotifyPrivate(pi.Name);
            NotifyPrivate("Error");
            NotifyToString();

            ClearTemporalError(pi.Name);

            return(true);
        }