示例#1
0
        /// <summary>
        /// 根据冗余路径从当前对象开始搜索,获取真实的属性值。
        /// </summary>
        /// <param name="path"></param>
        /// <param name="from">
        /// 本对象在路径中拥有的引用属性。
        /// 在 D->C->B->A.Name 场景中,当前对象(this)可能是 C,那么 from 就是 C.BRefProperty.
        /// 如果没有指定此属性,则表示从第一个开始。
        /// </param>
        /// <returns></returns>
        internal object GetRedundancyValue(RedundantPath path, IRefIdProperty from = null)
        {
            Entity refEntity = this;

            foreach (var refP in path.RefPathes)
            {
                if (from != null && refP.Property != from)
                {
                    continue;
                }

                refEntity = refEntity.GetRefEntity((refP.Property as IRefProperty).RefEntityProperty);
                if (refEntity == null)
                {
                    break;
                }
            }

            object value = null;

            if (refEntity != this && refEntity != null)
            {
                value = refEntity.GetProperty(path.ValueProperty.Property);
            }

            return(value);
        }
示例#2
0
文件: Property.cs 项目: yungtau/oea
        /// <summary>
        /// 声明本属性为只读属性
        /// </summary>
        /// <param name="path">The path.</param>
        /// <exception cref="System.InvalidOperationException">
        /// 属性已经注册完毕,不能修改!
        /// or
        /// 冗余属性不能被其它冗余属性再次冗余,请直接写全冗余路径。
        /// </exception>
        internal void AsRedundantOf(RedundantPath path)
        {
            if (this.GlobalIndex >= 0)
            {
                throw new InvalidOperationException("属性已经注册完毕,不能修改!");
            }
            if ((path.ValueProperty.Property as IProperty).IsRedundant)
            {
                throw new InvalidOperationException("冗余属性不能被其它冗余属性再次冗余,请直接写全冗余路径。");
            }
            if (!path.RefPathes[0].Owner.IsAssignableFrom(this.OwnerType))
            {
                throw new InvalidOperationException(path.RefPathes[0].FullName + "作为冗余路径中的第一个引用属性,必须和冗余属性同在一个实体类型中。");
            }

            var list = (path.ValueProperty.Property as IPropertyInternal).InRedundantPathes;

            list.Add(path);

            foreach (var refProperty in path.RefPathes)
            {
                (refProperty.Property as IPropertyInternal).InRedundantPathes.Add(path);
            }

            this._redundantPath = path;
            path.Redundancy     = new ConcreteProperty(this);
        }
示例#3
0
文件: P.cs 项目: yungtau/oea
        /// <summary>
        /// 注册一个冗余属性
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="propertyExp"></param>
        /// <param name="path">属性冗余的路径</param>
        /// <returns></returns>
        /// 不使用 lambda 表达式来注册冗余路径,这是因为可能会与属性生命周期冲突,同时也没有这个必要。
        public static Property <TProperty> RegisterRedundancy <TProperty>(
            Expression <Func <TEntity, TProperty> > propertyExp, RedundantPath path)
        {
            var property = GetPropertyName(propertyExp);

            var mp = new Property <TProperty>(typeof(TEntity), property, new PropertyMetadata <TProperty>());

            mp.AsRedundantOf(path);

            ManagedPropertyRepository.Instance.RegisterProperty(mp);

            return(mp);
        }
示例#4
0
        /// <summary>
        /// 根据冗余路径从当前对象开始搜索,获取真实的属性值。
        /// </summary>
        /// <param name="path"></param>
        /// <param name="from">
        /// 本对象在路径中拥有的引用属性。
        /// 在 D->C->B->A.Name 场景中,当前对象(this)可能是 C,那么 from 就是 C.BRefProperty.
        /// 如果没有指定此属性,则表示从第一个开始。
        /// </param>
        /// <returns></returns>
        internal object GetRedundancyValue(RedundantPath path, IRefIdProperty from = null)
        {
            Entity refEntity = this;
            foreach (var refP in path.RefPathes)
            {
                if (from != null && refP.Property != from) continue;

                refEntity = refEntity.GetRefEntity((refP.Property as IRefProperty).RefEntityProperty);
                if (refEntity == null) break;
            }

            object value = null;
            if (refEntity != this && refEntity != null) value = refEntity.GetProperty(path.ValueProperty.Property);

            return value;
        }
示例#5
0
        /// <summary>
        /// 冗余路径中非首位的引用属性变化时引发的冗余值更新操作。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="path">The path.</param>
        /// <param name="refChanged">该引用属性值变化了</param>
        private void UpdateRedundancyByIntermidateRef(Entity entity, RedundantPath path, IRefIdProperty refChanged)
        {
            var newValue = entity.GetRedundancyValue(path, refChanged);

            //只要从开始到 refChanged 前一个
            var refPathes = new List <ConcreteProperty>(5);

            foreach (var refProperty in path.RefPathes)
            {
                if (refProperty.Property == refChanged)
                {
                    break;
                }
                refPathes.Add(refProperty);
            }

            this.UpdateRedundancy(entity, path.Redundancy, newValue, refPathes, entity.Id);
        }
示例#6
0
        /// <summary>
        /// 冗余路径中非首位的引用属的值作为值属性进行冗余,那么同样要进行值属性更新操作。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="path">The path.</param>
        /// <param name="refChanged">该引用属性值变化了</param>
        private void UpdateRedundancyByRefValue(Entity entity, RedundantPath path, IRefIdProperty refChanged)
        {
            var newValue = entity.GetProperty(refChanged);

            this.UpdateRedundancy(entity, path.Redundancy, newValue, path.RefPathes, entity.Id);
        }
示例#7
0
 private void UpdateRedundancyByValue(Entity entity, RedundantPath path, object newValue)
 {
     this.UpdateRedundancy(entity, path.Redundancy, newValue, path.RefPathes, entity.Id);
 }
示例#8
0
文件: P.cs 项目: zhuwansu/Rafy
        /// <summary>
        /// 注册一个冗余扩展属性
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="declareType">Type of the declare.</param>
        /// <param name="path">属性冗余的路径</param>
        /// <returns></returns>
        public static Property <TProperty> RegisterRedundancyExtension <TProperty>(string propertyName, Type declareType, RedundantPath path)
        {
            var mp = new Property <TProperty>(typeof(TEntity), declareType, propertyName, new PropertyMetadata <TProperty>());

            mp.AsRedundantOf(path);

            ManagedPropertyRepository.Instance.RegisterProperty(mp);

            return(mp);
        }
示例#9
0
 private void UpdateRedundancyByValue(Entity entity, RedundantPath path, object newValue)
 {
     UpdateRedundancy(entity, path.Redundancy, newValue, path.RefPathes, entity.Id);
 }
示例#10
0
        /// <summary>
        /// 冗余路径中非首位的引用属的值作为值属性进行冗余,那么同样要进行值属性更新操作。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="path">The path.</param>
        /// <param name="refChanged">该引用属性值变化了</param>
        private void UpdateRedundancyByRefValue(Entity entity, RedundantPath path, IRefIdProperty refChanged)
        {
            var newValue = entity.GetProperty(refChanged);

            this.UpdateRedundancy(entity, path.Redundancy, newValue, path.RefPathes, entity.Id);
        }
示例#11
0
        /// <summary>
        /// 冗余路径中非首位的引用属性变化时引发的冗余值更新操作。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="path">The path.</param>
        /// <param name="refChanged">该引用属性值变化了</param>
        private void UpdateRedundancyByIntermidateRef(Entity entity, RedundantPath path, IRefIdProperty refChanged)
        {
            var newValue = entity.GetRedundancyValue(path, refChanged);

            //只要从开始到 refChanged 前一个
            var refPathes = new List<ConcreteProperty>(5);
            foreach (var refProperty in path.RefPathes)
            {
                if (refProperty.Property == refChanged) break;
                refPathes.Add(refProperty);
            }

            this.UpdateRedundancy(entity, path.Redundancy, newValue, refPathes, entity.Id);
        }