예제 #1
0
        /// <summary>
        /// Get change state by comparing old and new values.
        /// </summary>
        /// <param name="type">Type of values.</param>
        /// <param name="oldValue">Old value.</param>
        /// <param name="newValue">New value.</param>
        /// <returns></returns>
        public static ChangeState GetValueChangeSet(Type type, object oldValue, object newValue)
        {
            ChangeState state = new ChangeState();

            state.ValueType = type;
            state.oldValue  = oldValue;
            state.newValue  = newValue;
            state.State     = System.Data.EntityState.Unchanged;
            if (oldValue != newValue)
            {
                state.State = System.Data.EntityState.Modified;
            }
            bool oldIsEmpty = oldValue == null || oldValue == Activator.CreateInstance(type);
            bool newIsEmpty = newValue == null || newValue == Activator.CreateInstance(type);

            if (oldIsEmpty && !newIsEmpty)
            {
                state.State = System.Data.EntityState.Added;
            }
            if (newIsEmpty && !oldIsEmpty)
            {
                state.State = System.Data.EntityState.Deleted;
            }
            return(state);
        }
예제 #2
0
파일: Helper.cs 프로젝트: JocysCom/PassGen
 /// <summary>
 /// Get change state by comparing old and new values.
 /// </summary>
 /// <param name="type">Type of values.</param>
 /// <param name="oldValue">Old value.</param>
 /// <param name="newValue">New value.</param>
 /// <returns></returns>
 public static ChangeState GetValueChangeSet(Type type, object oldValue, object newValue)
 {
     ChangeState state = new ChangeState();
     state.ValueType = type;
     state.oldValue = oldValue;
     state.newValue = newValue;
     state.State = System.Data.EntityState.Unchanged;
     if (oldValue != newValue) state.State = System.Data.EntityState.Modified;
     bool oldIsEmpty = oldValue == null || oldValue == Activator.CreateInstance(type);
     bool newIsEmpty = newValue == null || newValue == Activator.CreateInstance(type);
     if (oldIsEmpty && !newIsEmpty) state.State = System.Data.EntityState.Added;
     if (newIsEmpty && !oldIsEmpty) state.State = System.Data.EntityState.Deleted;
     return state;
 }