GoDigram for .NET Framework and .NET Core
Northwoods.Go Namespace / GoDocument Class / ChangeValue Method
this value's Hint property identifies the kind of document change
true if this method should restore the older/previous state from before the change event; false if this method should restore the newer/next state from after the change event
Example
In This Topic
    ChangeValue Method (GoDocument)
    In This Topic
    This method is called by GoChangedEventArgs in order to perform the Undo or Redo or a particular document change.
    Syntax
    public virtual void ChangeValue( 
       GoChangedEventArgs e,
       bool undo
    )

    Parameters

    e
    this value's Hint property identifies the kind of document change
    undo
    true if this method should restore the older/previous state from before the change event; false if this method should restore the newer/next state from after the change event
    Remarks

    This handles changes to the document, such as ChangedAllowMove; to the collection of document layers, such as GoLayerCollection.InsertedLayer; and to any document layer, such as GoLayer.InsertedObject. For a GoLayer.ChangedObject event hint, this just calls GoObject.ChangeValue on the GoObject, to handle all the changes for objects such as GoObject.ChangedMovable. This method will raise an ArgumentException if the argument e's Hint value is not recognized.

    If you add a property to a class inheriting from GoDocument, you may want to override this method in order to handle undo/redo. Be sure to call the base method for all Hint values that your override 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 similarly, 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 document. You should check this property before making "unrelated" side-effects.

    Example
    Typical usage might be something like:
    public bool MaintainsPartID {
      get { return myMaintainsPartID; }
      set {
        // only set the value and do other things if the value has changed
        bool old = myMaintainsPartID;
        if (old != value) {
          myMaintainsPartID = value;
          // notify about the change
          RaiseChanged(ChangedMaintainsPartID, 0, null, 0, old, NullRect, 0, value, NullRect);
          // when set to true, and when not undoing/redoing, make sure all parts have unique IDs
          if (!this.Initializing) {
            if (value)
              EnsureUniquePartID();
            else
              ClearPartIDTable();
          }
        }
      }
    }
                
    public override void ChangeValue(GoChangedEventArgs e, bool undo) {
      switch (e.SubHint) {
        case ChangedMaintainsPartID:
          this.MaintainsPartID = (bool)e.GetValue(undo);
          return;
        default:
          base.ChangeValue(e, undo);
          return;
      }
    }
    See Also