Ejemplo n.º 1
0
        /// <summary>
        /// 要通过数据判断值对象相等
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            var target = obj as ValueObject;

            if (target == null)
            {
                return(false);
            }

            var targetType = target.ObjectType;

            if (targetType != ObjectType)
            {
                return(false);
            }

            //对比所有领域属性
            var properties = DomainProperty.GetProperties(ObjectType);

            foreach (var property in properties)
            {
                if (!EqualsHelper.ObjectEquals(this.GetValue(property), target.GetValue(property)))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在有效的属性对象上执行方法,只有被加载了的对象才执行
        /// </summary>
        /// <param name="action"></param>
        private void InvokeProperties(Action <DomainObject> action)
        {
            var properties = DomainProperty.GetProperties(this.ObjectType);

            foreach (var property in properties)
            {
                switch (property.DomainPropertyType)
                {
                case DomainPropertyType.EntityObject:
                case DomainPropertyType.ValueObject:
                {
                    DomainObject obj = null;
                    if (TryGetValue <DomainObject>(property, ref obj))
                    {
                        action(obj);
                    }
                }
                break;

                case DomainPropertyType.EntityObjectList:
                case DomainPropertyType.ValueObjectList:
                {
                    IEnumerable list = null;
                    if (TryGetValue <IEnumerable>(property, ref list))
                    {
                        foreach (DomainObject obj in list)
                        {
                            action(obj);
                        }
                    }
                }
                break;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 是否有脏的属性
        /// </summary>
        /// <returns></returns>
        private bool HasDirtyProperty()
        {
            var properties = DomainProperty.GetProperties(this.ObjectType);

            foreach (var property in properties)
            {
                if (IsPropertyDirty(property))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private void ValidateProperties(IDomainObject obj, ValidationResult result)
        {
            var properties = DomainProperty.GetProperties(obj.GetType());

            foreach (var property in properties)
            {
                if (obj.IsPropertyDirty(property))
                {
                    //我们只用验证脏属性
                    ValidateProperty(obj, property, result);
                }
            }
        }
Ejemplo n.º 5
0
        public override int GetHashCode()
        {
            return(HashCoder.GetCode(ObjectType, (hashCodes) =>
            {
                var properties = DomainProperty.GetProperties(ObjectType);
                foreach (var property in properties)
                {
                    var propertyValue = this.GetValue(property);

                    hashCodes.Add(HashCoder <string> .GetCode(property.Name));
                    hashCodes.Add(HashCoder.GetCode(propertyValue));
                }
            }));
        }