Exemple #1
0
 public IntegrityCheck(ModifiableEntity me, Dictionary <string, string> errors)
 {
     this.TemporalId = me.temporalId;
     this.Type       = me.GetType();
     this.Id         = me is Entity e ? e.id : null;
     Errors          = errors ?? throw new ArgumentNullException(nameof(errors));
 }
Exemple #2
0
        public static object[] FieldsWithAttribute(ModifiableEntity entity)
        {
            TypeAttributePack pack = GetFieldsAndProperties(entity.GetType());

            if (pack == null)
            {
                return(EmptyArray);
            }

            return(pack.Fields.Select(f => f(entity)).ToArray());
        }
Exemple #3
0
        internal static MixinEntity?CreateMixins(ModifiableEntity mainEntity)
        {
            var types = GetMixinDeclarations(mainEntity.GetType());

            MixinEntity?result = null;

            foreach (var t in types)
            {
                result = Constructors[t](mainEntity, result);
            }

            return(result);
        }
Exemple #4
0
        public static string FindPropertyName(ModifiableEntity entity, object fieldValue)
        {
            TypeAttributePack pack = GetFieldsAndProperties(entity.GetType());

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

            int index = pack.Fields.IndexOf(f => f(entity) == fieldValue);

            if (index == -1)
            {
                return(null);
            }

            return(pack.PropertyNames[index]);
        }
Exemple #5
0
        protected virtual void SetParentEntity(ModifiableEntity p)
        {
            if (p != null && this.parentEntity != null && this.parentEntity != p)
            {
                throw new InvalidOperationException($"'{nameof(parentEntity)}' of '{this}'({this.GetType().TypeName()}) is still connected to '{parentEntity}'({parentEntity.GetType().TypeName()}), then can not be set to '{p}'({p.GetType().TypeName()})");
            }

            this.parentEntity = p;
        }
Exemple #6
0
        private 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();

                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();

                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();
            }
        }