ModelBase Class
Provides a base object for model classes or business objects, which can validate their state, have undo/redo capability and can support committable/revertible editing.
Namespace: KGySoft.ComponentModelAssembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0-preview.1
[SerializableAttribute]
public abstract class ModelBase : ValidatingObjectBase,
ICanUndoRedo, ICanUndo, IRevertibleChangeTracking, IChangeTracking, ICanEdit,
IEditableObject
<SerializableAttribute>
Public MustInherit Class ModelBase
Inherits ValidatingObjectBase
Implements ICanUndoRedo, ICanUndo, IRevertibleChangeTracking, IChangeTracking,
ICanEdit, IEditableObject
[SerializableAttribute]
public ref class ModelBase abstract : public ValidatingObjectBase,
ICanUndoRedo, ICanUndo, IRevertibleChangeTracking, IChangeTracking, ICanEdit,
IEditableObject
[<AbstractClassAttribute>]
[<SerializableAttribute>]
type ModelBase =
class
inherit ValidatingObjectBase
interface ICanUndoRedo
interface ICanUndo
interface IRevertibleChangeTracking
interface IChangeTracking
interface ICanEdit
interface IEditableObject
end
- Inheritance
- Object ObservableObjectBase PersistableObjectBase ValidatingObjectBase ModelBase
- Implements
- ICanEdit, ICanUndo, ICanUndoRedo, IChangeTracking, IEditableObject, IRevertibleChangeTracking
This class unifies the capabilities of
ValidatingObjectBase,
EditableObjectBase and
UndoableObjectBase classes.
If you don't need all of these features you can pick one of these classes as a base class for your business objects. If you need none of these features but only raising events about property changes
you can use the
ObservableObjectBase or
PersistableObjectBase classes.
See also the class diagram of the business object base classes of the
KGySoft.CoreLibraries assembly:
Differences from ValidatingObjectBase:
Though undo/redo and object editing are independent features, the undo history is cleared when an editing session is reverted by the RevertLastEdit or TryRevertAllEdits
methods to avoid confusion.
See the Remarks section of the ObservableObjectBase class for an example about how to define properties in a derived class.
See the Remarks section of the ValidatingObjectBase class for an example about how to validate properties in a derived class.
ModelBase | Initializes a new instance of the ModelBase class |
AffectsModifiedState |
Gets whether the change of the specified propertyName affects the IsModified property.
The ModelBase implementation excludes the IsModified, EditLevel, IsValid,
UndoCapacity, CanUndo and CanRedo properties.
(Overrides ValidatingObjectBaseAffectsModifiedState(String)) |
BeginNewEdit |
Begins a new level of committable/revertible editing session on the object.
|
CanGetProperty |
Gets whether the specified property can be retrieved.
The base implementation allows to get the actual instance properties in this instance.
(Inherited from ObservableObjectBase) |
CanSetProperty |
Gets whether the specified property can be set.
The base implementation allows to set the actual instance properties in this instance if the specified value is compatible with the property type.
(Inherited from ObservableObjectBase) |
ClearUndoHistory |
Clears the undo/redo history without performing any undo.
|
Clone |
Creates a new object that is a copy of the current instance.
The base implementation clones the internal property storage, the IsModified property and if clonePropertyChanged
is , then also the subscribers of the PropertyChanged event. It respects the
implementations with some special handling for arrays so arrays can be deep-cloned as well.
(Inherited from ObservableObjectBase) |
CommitLastEdit |
Commits all changes since the last BeginNewEdit call.
|
Dispose |
Releases the resources held by this instance.
(Inherited from ObservableObjectBase) |
Dispose(Boolean) |
Releases the resources held by this instance.
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.
(Inherited from ObservableObjectBase) |
DoValidation |
Performs the validation on this instance and returns the validation results. Must not return .
(Overrides ValidatingObjectBaseDoValidation) |
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.
For an example, see the Remarks section of the ObservableObjectBase class.
(Inherited from ObservableObjectBase) |
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.
For an example, see the Remarks section of the ObservableObjectBase class.
(Inherited from ObservableObjectBase) |
OnPropertyChanged |
Raises the PropertyChanged event.
(Overrides ValidatingObjectBaseOnPropertyChanged(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) |
RevertLastEdit |
Discards all changes since the last BeginNewEdit call.
|
Set |
Sets the value of a property.
For an example, see the Remarks section of the ObservableObjectBase class.
(Inherited from ObservableObjectBase) |
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) |
TryCommitAllEdits |
Commits all changes of all editing levels.
|
TryRedo |
Tries to perform one redo step.
|
TryRevertAllEdits |
Reverts all changes of all editing levels.
|
TryUndo |
Tries to perform one undo step.
|
UndoAll |
Undoes all possible undo steps.
|
Validate |
Forces calling the DoValidation method and updates the ValidationResults and IsValid properties.
(Inherited from ValidatingObjectBase) |