コード例 #1
0
        public IMemento Restore()
        {
            var memento = new NotifyCollectionChangeMemento
            {
                List     = List,
                Action   = GetInvertedAction(Action),
                OldIndex = NewIndex,
                OldValue = NewValue,
                NewIndex = OldIndex,
                NewValue = OldValue
            };

            switch (Action)
            {
            case NotifyCollectionChangeAction.Add:
                List.RemoveAt(NewIndex);
                break;

            case NotifyCollectionChangeAction.Remove:
                List.Insert(OldIndex, OldValue);
                break;

            case NotifyCollectionChangeAction.Replace:
                throw new NotImplementedException();
            }

            return(memento);
        }
コード例 #2
0
 private void LogCollectionChanged(NotifyCollectionChangeMemento memento, NotifyCollectionChangingEventArgs e)
 {
     if (!EventSettings.EnableLogging)
         return;
     
     if (InEditableObjectAction())
     {
         if (e.Action == NotifyCollectionChangeAction.Replace)
         {
             log.DebugFormat("adding collection change to edit action {0}: index:{1} {2} -> {3}", memento.Action,
                             memento.Index, memento.OldValue ?? "null", memento.NewValue ?? "null");
         }
         else
         {
             log.DebugFormat("adding collection change to edit action {0}: index:{1} {2}", memento.Action,
                             memento.Index, memento.NewValue ?? "null");
         }
     }
     else
     {
         if (e.Action == NotifyCollectionChangeAction.Replace)
         {
             log.DebugFormat("saving undo for collection change {0}: index:{1} {2} -> {3}", memento.Action,
                             memento.Index, memento.OldValue ?? "null", memento.NewValue ?? "null");
         }
         else
         {
             log.DebugFormat("saving undo for collection change {0}: index: {1} {2}", memento.Action,
                             memento.Index, memento.NewValue ?? "null");
         }
     }
 }