See the Remarks section for details.
KGySoft.ComponentModelObservableObjectBase
KGySoft.ComponentModelPersistableObjectBase
KGySoft.ComponentModelUndoableObjectBase
Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.5.0-rc.1
[SerializableAttribute] public abstract class UndoableObjectBase : PersistableObjectBase, ICanUndoRedo, ICanUndo, IRevertibleChangeTracking, IChangeTracking
The UndoableObjectBase type exposes the following members.
Name | Description | |
---|---|---|
![]() | UndoableObjectBase | Initializes a new instance of the UndoableObjectBase class |
Name | Description | |
---|---|---|
![]() | CanRedo |
Gets whether there are changes to redo.
|
![]() | CanUndo |
Gets whether there are changes to undo.
|
![]() | IsDisposed |
Gets whether this instance has already been disposed.
(Inherited from ObservableObjectBase.)See the Remarks section for details. |
![]() | IsModified |
Gets whether this instance has been modified.
Modified state can be set by the SetModified method.
(Inherited from ObservableObjectBase.) |
![]() | UndoCapacity |
Gets or sets the undo capacity.
Default value: 20. |
Name | Description | |
---|---|---|
![]() | AffectsModifiedState |
Gets whether the change of the specified propertyName affects the IsModified property.
(Overrides ObservableObjectBaseAffectsModifiedState(String).)The UndoableObjectBase implementation excludes the IsModified, UndoCapacity, CanUndo and CanRedo properties. |
![]() | CanGetProperty |
Gets whether the specified property can be retrieved.
(Inherited from ObservableObjectBase.)The base implementation allows to get the actual instance properties in this instance. |
![]() | CanSetProperty |
Gets whether the specified property can be set.
(Inherited from ObservableObjectBase.)The base implementation allows to set the actual instance properties in this instance if the specified value is compatible with the property type. |
![]() | ClearUndoHistory |
Clears the undo/redo history without performing any undo.
|
![]() | Clone |
Creates a new object that is a copy of the current instance.
(Inherited from ObservableObjectBase.)The base implementation clones the internal property storage, the IsModified property and if clonePropertyChanged is , then also the subscribers of the PropertyChanged event. |
![]() | Dispose |
Releases the resources held by this instance.
(Inherited from ObservableObjectBase.) |
![]() | Dispose(Boolean) |
Releases the resources held by this instance.
(Inherited from ObservableObjectBase.)The base implementation removes the subscribers of the PropertyChanged event and clears the property storage. If the overridden method disposes properties accessed by the Get<T> and Set methods, then check the IsDisposed property first and call the base method as the last step to prevent ObjectDisposedException. |
![]() | GetT(FuncT, String) |
Gets the value of a property, or - if it was not set before -, then creates its initial value.
The created initial value will be stored in the internal property storage without triggering the PropertyChanged event.
For constant or simple expressions, or to return a default value for a non-existing property without storing it internally use the other Get overload.
(Inherited from ObservableObjectBase.)For an example, see the Remarks section of the ObservableObjectBase class. |
![]() | GetT(T, String) |
Gets the value of a property or defaultValue if no value is stored for it. No new value will be stored
if the property does not exist. If the default initial value is too complex and should not be evaluated every time when the property is get,
or to throw an exception for an uninitialized property use the other Get overload.
(Inherited from ObservableObjectBase.)For an example, see the Remarks section of the ObservableObjectBase class. |
![]() | OnPropertyChanged |
Raises the PropertyChanged event.
(Overrides ObservableObjectBaseOnPropertyChanged(PropertyChangedExtendedEventArgs).) |
![]() | RedoAll |
Redoes all possible redo steps.
|
![]() | ResetProperty |
Resets the property of the specified name, meaning, it will be removed from the underlying storage so the getter methods will return the default value again.
(Inherited from ObservableObjectBase.) |
![]() | ResumeChangedEvent |
Resumes the raising of the PropertyChanged event suspended by the SuspendChangeEvents method.
(Inherited from ObservableObjectBase.) |
![]() | Set |
Sets the value of a property.
(Inherited from ObservableObjectBase.)For an example, see the Remarks section of the ObservableObjectBase class. |
![]() | SetModified |
Sets the modified state of this ObservableObjectBase instance represented by the IsModified property.
(Inherited from ObservableObjectBase.) |
![]() | SuspendChangedEvent |
Suspends the raising of the PropertyChanged event until ResumeChangeEvents
method is called. Supports nested calls.
(Inherited from ObservableObjectBase.) |
![]() | TryRedo |
Tries to perform one redo step.
|
![]() | TryUndo |
Tries to perform one undo step.
|
![]() | UndoAll |
Undoes all possible undo steps.
|
Name | Description | |
---|---|---|
![]() | PropertyChanged |
Occurs when a property value changed. The actual type of the event argument is PropertyChangedExtendedEventArgs.
(Inherited from ObservableObjectBase.) |
Name | Description | |
---|---|---|
![]() | Convert(Type, CultureInfo) | Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example. |
![]() ![]() | ConvertTTarget(CultureInfo) | Overloaded. (Defined by ObjectExtensions.) |
![]() | In |
Gets whether item is among the elements of set.
(Defined by ObjectExtensions.)See the Examples section of the generic InT(T, T) overload for an example. |
![]() | TryConvert(Type, Object) | Overloaded. (Defined by ObjectExtensions.) |
![]() | TryConvert(Type, CultureInfo, Object) | Overloaded. (Defined by ObjectExtensions.) |
![]() | TryConvertTTarget(TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvertTTarget(CultureInfo, TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
An object derived from UndoableObjectBase continuously tracks the property changes of properties, which are set through the IPersistableObject implementation and the ObservableObjectBase.Set method.
![]() |
---|
When it is needed to be determined whether a type has undo/redo capability use the ICanUndo or ICanUndoRedo interfaces instead the UndoableObjectBase type because other undoable types, such as the ModelBase class are not necessarily derived from the UndoableObjectBase class. See also the class diagram of the business object base classes of the KGySoft.CoreLibraries assembly: |

Differences from EditableObjectBase:
Both UndoableObjectBase and EditableObjectBase can revert changes; however, the aspects of these classes are different.
- An undoable class (which implements ICanUndo or ICanUndoRedo interfaces such as UndoableObjectBase) is able to undo (or redo) any changes made so far either step-by-step or in a single step.
- On the other hand, an editable class (which implements ICanEdit such as EditableObjectBase) is able to start editing sessions by saving a snapshot of its current state, which states are committable and revertible.
- Undo and editing features are independent from each other and a class is allowed to implement both (like the ModelBase class).
IRevertibleChangeTracking support:
UndoableObjectBase implements also the System.ComponentModel.IRevertibleChangeTracking interface, which is the standard way in .NET to support undoing.
This is how the IRevertibleChangeTracking members are mapped in the UndoableObjectBase class:
- IChangeTracking.IsChanged: Returns CanUndo.
- IChangeTracking.AcceptChanges: Calls ClearUndoHistory.
- IRevertibleChangeTracking.RejectChanges: Calls UndoAll.
IsModified vs. CanUndo:
- The IsModified property reflects the object's "dirty" state, meaning, it has been changed since the initialization or last save. The modified state can be cleared by the SetModified method. Clearing the modified state (eg. on saving the object) does not affect the undo capabilities, though.
- The CanUndo property tells whether there are any steps to undo. On saving an object the modified state can be cleared and still there can be undoable steps. And vice versa, undoing all steps will not clear the modified state.
![]() |
---|
For an example see the Remarks section of the ObservableObjectBase class. The same applies also for the UndoableObjectBase class in terms of implementation. |