Beispiel #1
0
 /// <summary>
 /// 判断属性是否需要纠正默认值的类型。
 /// </summary>
 /// <param name="property"></param>
 /// <returns></returns>
 private static bool IsNeedCorrectDefaultValue(IProperty property)
 {
     return(!PropertyValue.IsEmpty(property.Info.DefaultValue) &&
            (property.Type.IsEnum || property.Type == typeof(bool) || property.Type == typeof(bool?)));
 }
Beispiel #2
0
        /// <summary>
        /// 检查有没有关联属性被修改.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private bool CheckRelationHasModified(IEntity entity)
        {
            //判断实体类型有是不是编译的代理类型,如果不是,取非null的属性,否则使用IsModified判断
            var isNotCompiled = entity.GetType().IsNotCompiled();

            return(PropertyUnity.GetRelatedProperties(entity.EntityType).Any(s => isNotCompiled ? !PropertyValue.IsEmpty(entity.GetValue(s)) : entity.IsModified(s.Name)));
        }
Beispiel #3
0
        /// <summary>
        /// 检查实体的关联属性。
        /// </summary>
        /// <param name="entity"></param>
        private async Task HandleRelationPropertiesAsync(IEntity entity, CancellationToken cancellationToken = default)
        {
            //判断实体类型有是不是编译的代理类型,如果不是,取非null的属性,否则使用IsModified判断
            var isNotCompiled = entity.GetType().IsNotCompiled();
            var properties    = PropertyUnity.GetRelatedProperties(entity.EntityType).Where(m => isNotCompiled ?
                                                                                            !PropertyValue.IsEmpty(entity.GetValue(m)) :
                                                                                            entity.IsModified(m.Name));

            await HandleRelationPropertiesAsync(entity, properties, cancellationToken);
        }
Beispiel #4
0
        /// <summary>
        /// 检查 EntitySet 里的元素是还被销毁。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        private bool CheckEntitySetDestroy(IProperty property, PropertyValue oldValue, PropertyValue newValue)
        {
            if (!property.Is <EntitySetProperty>())
            {
                return(false);
            }

            if (PropertyValue.IsEmpty(oldValue))
            {
                oldValue = ProcessSupposedProperty(property);
            }

            if (!PropertyValue.IsEmpty(oldValue) && PropertyValue.IsEmpty(newValue))
            {
                var oldSet = oldValue.GetValue() as IEntitySet;
                if (oldSet != null)
                {
                    oldSet.Clear();
                }

                if (!PropertyValue.IsEmpty(newValue))
                {
                    var newSet = newValue.GetValue() as IEntitySet;
                    if (newSet != null)
                    {
                        newSet.ShiftDetachedList(oldSet);
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// 设置实体指定属性的值。判断实体是否实现了 <see cref="IEntityPropertyAccessor"/> 接口。
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="property"></param>
        /// <param name="value"></param>
        internal static void InternalSetValue(this IEntity entity, IProperty property, PropertyValue value)
        {
            var accessor = entity as IEntityPropertyAccessor;

            if (accessor != null)
            {
                accessor.SetValue(property, value);
            }
            else
            {
                entity.SetValue(property.Name, value);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 设置属性值。
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public override void SetValue(IProperty property, PropertyValue value)
 {
     property.Info.ReflectionInfo.SetValue(this, value.GetValue(), null);
 }
Beispiel #7
0
        /// <summary>
        /// 检查客户端是否取消属性值的更改。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <param name="oldValue"></param>
        /// <returns></returns>
        private bool CheckPropertyChangingIsCanceled(IProperty property, PropertyValue value, PropertyValue oldValue)
        {
            var changingArgs = new PropertyChangingEventArgs(property, oldValue, value);

            OnPropertyChanging(changingArgs);
            return(changingArgs.Cancel);
        }
Beispiel #8
0
 /// <summary>
 /// 初始化属性的值。
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 protected void ProtectInitializeValue(IProperty property, PropertyValue value)
 {
     base.InitializeValue(property, value);
 }
Beispiel #9
0
        /// <summary>
        /// 获取属性值。
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public override PropertyValue GetValue(IProperty property)
        {
            var value = property.Info.ReflectionInfo.GetValue(this, null);

            return(value == null ? PropertyValue.Empty : PropertyValue.NewValue(value, property.Type));
        }
Beispiel #10
0
 /// <summary>
 /// 初始化属性的值。
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public override void InitializeValue(IProperty property, PropertyValue value)
 {
     this.SetValue(property, value);
 }
Beispiel #11
0
 /// <summary>
 /// 使用保护方式设置属性的值。
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 protected void ProtectSetValue(IProperty property, PropertyValue value)
 {
     base.SetValue(property, value);
 }
Beispiel #12
0
 /// <summary>
 /// 使用指定的值进行修改。
 /// </summary>
 /// <param name="value"></param>
 internal void Modify(PropertyValue value)
 {
     _newValue  = value;
     IsModified = true;
 }
Beispiel #13
0
 /// <summary>
 /// 使用新值初始化一个 <see cref="EntityEntry"/>。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 internal static EntityEntry InitByNewValue(PropertyValue value)
 {
     return(new EntityEntry {
         _newValue = value, IsModified = true
     });
 }
Beispiel #14
0
 /// <summary>
 /// 使用旧值初始化一个 <see cref="EntityEntry"/>。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 internal static EntityEntry InitByOldValue(PropertyValue value)
 {
     return(new EntityEntry {
         _oldValue = value
     });
 }
Beispiel #15
0
 /// <summary>
 /// 获取指定 <see cref="PropertyValue"/> 真实的值。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static TValue GetValue <TValue>(PropertyValue value)
 {
     if (IsEmpty(value))
     {
         return(default);
Beispiel #16
0
 /// <summary>
 /// 获取指定 <see cref="PropertyValue"/> 真实的值。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static object GetValue(PropertyValue value)
 {
     return(IsEmpty(value) ? null : value.GetValue());
 }