GoDigram for .NET Framework and .NET Core
Northwoods.Go Namespace / GoObject Class / ChangeValue Method
The particular GoChangedEventArgs edit.
If true, restore the old value, otherwise restore the new value.
Example
In This Topic
    ChangeValue Method (GoObject)
    In This Topic
    Perform an undo or redo, given a GoChangedEventArgs representing a change on this object.
    Syntax
    public virtual void ChangeValue( 
       GoChangedEventArgs e,
       bool undo
    )

    Parameters

    e
    The particular GoChangedEventArgs edit.
    undo
    If true, restore the old value, otherwise restore the new value.
    Remarks

    If you override this method, be sure to call the base method for all SubHint values that your override method does not handle.

    Although properties should be designed so that setting one property does not modify other properties, this is sometimes not practical. Nevertheless it is important to avoid having side-effects when the value is changing due to an undo or redo. One way of doing this is to copy the needed code, but not the auxiliary side-effecting code, from the property setter to the ChangeValue override. Or you could define a method called from both the setter and the ChangeValue method, parameterized by whether the caller is the setter or not.

    But a more convenient way to achieve this is to check the Initializing property that is set to true when the ChangeValue method is being called on this object. You should check this property before making "unrelated" side-effects.

    Example
    Typical usage might be something like:
    public bool Orthogonal {
      get { return myOrthogonal; }
      set {
        // only set the value and do other things if the value has changed
        bool old = myOrthogonal;
        if (old != value) {
          myOrthogonal = value;
          // maybe clear out some internal cached state too
          ResetStuff();
          // notify about the change
          Changed(ChangedOrthogonal, 0, old, NullRect, 0, value, NullRect);
          // when set to true, and when not undoing/redoing, recalculate the stroke
          if (value && !this.Initializing) {
            ClearPoints();
            CalculateRoute();
          }
        }
      }
    }
                
    public override void ChangeValue(GoChangedEventArgs e, bool undo) {
      switch (e.SubHint) {
        case ChangedOrthogonal: {
          this.Orthogonal = (bool)e.GetValue(undo);
          return; }
        default:
          base.ChangeValue(e, undo);
          return;
      }
    }
    See Also