Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PropertyChangedActionItem.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Reflection;
5 
6 namespace SiliconStudio.ActionStack
7 {
9  {
10  private readonly string propertyName;
11  private object container;
12  private object previousValue;
13 
14  public PropertyChangedActionItem(string propertyName, object container, object previousValue)
15  {
16  if (propertyName == null) throw new ArgumentNullException("propertyName");
17  if (container == null) throw new ArgumentNullException("container");
18  this.propertyName = propertyName;
19  this.container = container;
20  this.previousValue = previousValue;
21  }
22 
23  /// <summary>
24  /// Gets the name of the property affected by the change.
25  /// </summary>
26  public string PropertyName { get { return propertyName; } }
27 
28  /// <inheritdoc/>
29  protected override void FreezeMembers()
30  {
31  container = null;
32  previousValue = null;
33  }
34 
35  /// <inheritdoc/>
36  protected override void UndoAction()
37  {
38  PropertyInfo propertyInfo = container.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
39  object value = previousValue;
40  previousValue = propertyInfo.GetValue(container);
41  propertyInfo.SetValue(container, value);
42  }
43 
44  /// <inheritdoc/>
45  protected override void RedoAction()
46  {
47  // Once we have un-done, the previous value is updated so Redo is just Undoing the Undo
48  UndoAction();
49  }
50  }
51 }
PropertyChangedActionItem(string propertyName, object container, object previousValue)
Base class for action items.
Definition: ActionItem.cs:13
override void UndoAction()
Invoked by Undo after setting IsDone to true.
override void FreezeMembers()
Invoked by Freeze before setting IsFrozen to true. This method will not be invoked if IsFrozen is alr...
override void RedoAction()
Invoked by Redo after setting IsDone to true.