C# Class Catel.Data.ModelBase

Show file Open project: Catel/Catel Class Usage Examples

Public Properties

Property Type Description
IsDirtyProperty PropertyData
IsReadOnlyProperty PropertyData

Private Properties

Property Type Description
CatchUpWithSuspendedAnnotationsValidation void
ClearIsDirtyOnAllChilds void
EnsureValidationIsUpToDate void
FinishInitializationAfterConstructionOrDeserialization void
GetObjectData void
GetValidator IValidator
HandleObjectEventsSubscription void
IEditableObject void
IModelValidation void
INotifyDataErrorInfo IEnumerable
INotifyDataWarningInfo IEnumerable
IXmlSerializable XmlSchema
IXmlSerializable void
IXmlSerializable void
Initialize void
ModelBase System
NotifyErrorsChanged void
NotifyWarningsChanged void
OnDeserialized void
OnValidated void
OnValidatedBusinessRules void
OnValidatedFields void
OnValidating void
OnValidatingBusinessRules void
OnValidatingFields void
RaisePropertyChanged void
RaisePropertyChangedForAllRegisteredProperties void
SetBusinessRuleValidationResult void
SetFieldValidationResult void
ValidatePropertyUsingAnnotations bool
this stringIDataErrorInfo.Runtime.Serialization
this stringIDataWarningInfo.Runtime.Serialization

Public Methods

Method Description
Equals ( object obj ) : bool

Determines whether the specified System.Object is equal to this instance.

GetHashCode ( ) : int

Returns a hash code for this instance.

SuspendChangeCallbacks ( ) : IDisposable

Suspends the change callbacks whenever a property has been called. This is very useful when there are expensive property change callbacks registered with a property that need to be temporarily disabled.

SuspendChangeNotifications ( bool raiseOnResume = true ) : IDisposable

Suspends the change notifications until the disposed object has been released.

SuspendValidations ( bool validateOnResume = true ) : IDisposable

Suspends the validation until the disposable token has been disposed.

ToString ( ) : string

Returns a System.String that represents this instance.

Validate ( bool force, bool validateDataAnnotations ) : void

Validates the current object for field and business rule errors.

To check whether this object contains any errors, use the INotifyDataErrorInfo.HasErrors property.

operator ( ) : bool

Implements the operator ==.

Protected Methods

Method Description
ClearIsDirtyOnAllChilds ( ) : void

Clears the IsDirty on all childs.

GetBusinessRuleErrors ( ) : string

Gets the current errors errors.

GetBusinessRuleWarnings ( ) : string

Gets the current business warnings.

GetFieldErrors ( string columnName ) : string

Gets the errors for a specific column.

GetFieldWarnings ( string columnName ) : string

Gets the warnings for a specific column.

InitializeCustomProperties ( ) : void

Allows the initialization of custom properties. This is a virtual method that is called inside the constructor before the object is fully constructed. This might be considered as bad or as a hack, but it's a good way to be able to inject custom properties before any actual logic is handled by derived classes.

Only use when you really know what you are doing.

ModelBase ( SerializationInfo info, StreamingContext context ) : Catel.IoC

Initializes a new instance of the ModelBase class. Only constructor for the ModelBase.

Call this method, even when constructing the object for the first time (thus not deserializing).

NotifyValidationResult ( IValidationResult validationResult, bool notifyGlobal ) : void

Raises the right events based on the validation result.

OnBeginEdit ( System.ComponentModel.BeginEditEventArgs e ) : void

Raises the IEditableObject.BeginEdit event.

OnCancelEdit ( System.ComponentModel.EditEventArgs e ) : void

Raises the IEditableObject.CancelEdit event.

OnCancelEditCompleted ( System.ComponentModel.CancelEditCompletedEventArgs e ) : void

Raises the IAdvancedEditableObject.CancelEditingCompleted event.

OnEndEdit ( System.ComponentModel.EditEventArgs e ) : void

Raises the IEditableObject.EndEdit event.

OnInitialized ( ) : void

Called when the object is initialized.

OnInitializing ( ) : void

Called when the object is being initialized.

OnPropertyObjectCollectionChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void

Called when a property that implements INotifyCollectionChanged raises the event.

OnPropertyObjectCollectionItemPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void

Called when a property inside a collection that implements INotifyCollectionChanged that implements INotifyPropertyChanged raises the event.

OnPropertyObjectPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void

Called when a property that implements INotifyPropertyChanged raises the event.

OnValidated ( IValidationContext validationContext ) : void

Called when the object is validated.

OnValidatedBusinessRules ( IValidationContext validationContext ) : void

Called when the object has validated the business rules.

OnValidatedFields ( IValidationContext validationContext ) : void

Called when the object has validated the fields.

OnValidating ( IValidationContext validationContext ) : void

Called when the object is validating.

OnValidatingBusinessRules ( IValidationContext validationContext ) : void

Called when the object is validating the business rules.

OnValidatingFields ( IValidationContext validationContext ) : void

Called when the object is validating the fields.

RaisePropertyChanged ( object sender, Catel.Data.AdvancedPropertyChangedEventArgs e ) : void

Raises the INotifyPropertyChanged.PropertyChanged event.

This method is overriden en does not call the base because lots of additional logic is added in this class. The RaisePropertyChanged(object,System.ComponentModel.PropertyChangedEventArgs,bool,bool) will explicitly call ObservableObject.RaisePropertyChanged(object, AdvancedPropertyChangedEventArgs). If this method is overriden, it is very important to call the base.

SetDirtyAndAutomaticallyValidate ( string propertyName, bool setDirtyAndAllowAutomaticValidation ) : void

Sets the IsDirty property and automatically validate if required.

SetParent ( IParent parent ) : void

Sets the new parent of this object.

ShouldPropertyChangeUpdateIsDirty ( string propertyName ) : bool

Determines whether a specific property change should update IsDirty to true.

Validate ( bool force = false ) : void

Validates the current object for field and business rule errors.

To check whether this object contains any errors, use the INotifyDataErrorInfo.HasErrors property.

ValidateBusinessRules ( List validationResults ) : void

Validates the business rules of this object. Override this method to enable validation of business rules.

ValidateFields ( List validationResults ) : void

Validates the field values of this object. Override this method to enable validation of field values.

Private Methods

Method Description
CatchUpWithSuspendedAnnotationsValidation ( ) : void

Catches up with suspended annotations validation. This method will take care of unvalidated properties that have been changed during the suspended validation state of this model.

ClearIsDirtyOnAllChilds ( object obj, HashSet handledReferences ) : void

Clears the IsDirty on all childs.

EnsureValidationIsUpToDate ( bool constraint = true ) : void

Ensures the validation is up to date.

FinishInitializationAfterConstructionOrDeserialization ( ) : void

Finishes the initialization after construction or deserialization.

GetObjectData ( SerializationInfo info, StreamingContext context ) : void
GetValidator ( ) : IValidator

Gets the validator. If the field is null, it will query the service locator.

HandleObjectEventsSubscription ( string propertyName, object propertyValue ) : void

Handles the object events subscription. This means that the old value will be removed from the event subscriptions, and the new value will be subscribed to.

IEditableObject ( ) : void

Begins an edit on an object.

IModelValidation ( bool force ) : void

Validates the current object for field and business rule errors.

To check whether this object contains any errors, use the INotifyDataErrorInfo.HasErrors property.

INotifyDataErrorInfo ( string propertyName ) : IEnumerable

Gets the validation errors for a specified property or for the entire object.

INotifyDataWarningInfo ( string propertyName ) : IEnumerable

Gets the warnings for the specific property name.

IXmlSerializable ( ) : XmlSchema

This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the T:System.Xml.Serialization.XmlSchemaProviderAttribute to the class.

IXmlSerializable ( XmlReader reader ) : void

Generates an object from its XML representation.

IXmlSerializable ( XmlWriter writer ) : void

Converts an object into its XML representation.

Initialize ( ) : void

Initializes the object by setting default values.

ModelBase ( ) : System

Initializes static members of the ModelBase class.

NotifyErrorsChanged ( string propertyName, bool notifyHasErrors ) : void

Notifies all listeners that the errors for the specified property have changed. If the propertyName is null or string.Empty, the business errors will be updated.

NotifyWarningsChanged ( string propertyName, bool notifyHasWarnings ) : void

Notifies all listeners that the warnings for the specified property have changed. If the propertyName is null or string.Empty, the business errors will be updated.

OnDeserialized ( StreamingContext context ) : void
OnValidated ( ) : void
OnValidatedBusinessRules ( ) : void
OnValidatedFields ( ) : void
OnValidating ( ) : void
OnValidatingBusinessRules ( ) : void
OnValidatingFields ( ) : void
RaisePropertyChanged ( object sender, PropertyChangedEventArgs e, bool setDirtyAndAllowAutomaticValidation, bool isRefreshCallOnly ) : void

Invoked when a property value has changed.

RaisePropertyChangedForAllRegisteredProperties ( ) : void

Invokes the property changed for all registered properties.

Using this method does not set the IsDirty property to true, nor will it cause the object to validate itself automatically, even when the AutomaticallyValidateOnPropertyChanged is set to true.

SetBusinessRuleValidationResult ( IBusinessRuleValidationResult validationResult ) : void
SetFieldValidationResult ( IFieldValidationResult validationResult ) : void
ValidatePropertyUsingAnnotations ( string propertyName, object value, PropertyData catelPropertyData ) : bool

Validates the property using data annotations.

this ( string columnName ) : stringIDataErrorInfo.Runtime.Serialization

Gets an error for a specific column.

this ( string columnName ) : stringIDataWarningInfo.Runtime.Serialization

Gets a warning for a specific column.

Method Details

ClearIsDirtyOnAllChilds() protected method

Clears the IsDirty on all childs.
protected ClearIsDirtyOnAllChilds ( ) : void
return void

Equals() public method

Determines whether the specified System.Object is equal to this instance.
/// The parameter is null. ///
public Equals ( object obj ) : bool
obj object The to compare with this instance.
return bool

GetBusinessRuleErrors() protected method

Gets the current errors errors.
protected GetBusinessRuleErrors ( ) : string
return string

GetBusinessRuleWarnings() protected method

Gets the current business warnings.
protected GetBusinessRuleWarnings ( ) : string
return string

GetFieldErrors() protected method

Gets the errors for a specific column.
protected GetFieldErrors ( string columnName ) : string
columnName string Column name.
return string

GetFieldWarnings() protected method

Gets the warnings for a specific column.
protected GetFieldWarnings ( string columnName ) : string
columnName string Column name.
return string

GetHashCode() public method

Returns a hash code for this instance.
public GetHashCode ( ) : int
return int

InitializeCustomProperties() protected method

Allows the initialization of custom properties. This is a virtual method that is called inside the constructor before the object is fully constructed. This might be considered as bad or as a hack, but it's a good way to be able to inject custom properties before any actual logic is handled by derived classes.
Only use when you really know what you are doing.
protected InitializeCustomProperties ( ) : void
return void

ModelBase() protected method

Initializes a new instance of the ModelBase class. Only constructor for the ModelBase.
Call this method, even when constructing the object for the first time (thus not deserializing).
protected ModelBase ( SerializationInfo info, StreamingContext context ) : Catel.IoC
info SerializationInfo SerializationInfo object, null if this is the first time construction.
context StreamingContext StreamingContext object, simple pass a default new StreamingContext() if this is the first time construction.
return Catel.IoC

NotifyValidationResult() protected method

Raises the right events based on the validation result.
The is null.
protected NotifyValidationResult ( IValidationResult validationResult, bool notifyGlobal ) : void
validationResult IValidationResult The validation result.
notifyGlobal bool If set to true, the global properties such as and are also raised.
return void

OnBeginEdit() protected method

Raises the IEditableObject.BeginEdit event.
protected OnBeginEdit ( System.ComponentModel.BeginEditEventArgs e ) : void
e System.ComponentModel.BeginEditEventArgs The instance containing the event data.
return void

OnCancelEdit() protected method

Raises the IEditableObject.CancelEdit event.
protected OnCancelEdit ( System.ComponentModel.EditEventArgs e ) : void
e System.ComponentModel.EditEventArgs The instance containing the event data.
return void

OnCancelEditCompleted() protected method

Raises the IAdvancedEditableObject.CancelEditingCompleted event.
protected OnCancelEditCompleted ( System.ComponentModel.CancelEditCompletedEventArgs e ) : void
e System.ComponentModel.CancelEditCompletedEventArgs The instance containing the event data.
return void

OnEndEdit() protected method

Raises the IEditableObject.EndEdit event.
protected OnEndEdit ( System.ComponentModel.EditEventArgs e ) : void
e System.ComponentModel.EditEventArgs The instance containing the event data.
return void

OnInitialized() protected method

Called when the object is initialized.
protected OnInitialized ( ) : void
return void

OnInitializing() protected method

Called when the object is being initialized.
protected OnInitializing ( ) : void
return void

OnPropertyObjectCollectionChanged() protected method

Called when a property that implements INotifyCollectionChanged raises the event.
protected OnPropertyObjectCollectionChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void
sender object The sender.
e NotifyCollectionChangedEventArgs The instance containing the event data.
return void

OnPropertyObjectCollectionItemPropertyChanged() protected method

Called when a property inside a collection that implements INotifyCollectionChanged that implements INotifyPropertyChanged raises the event.
protected OnPropertyObjectCollectionItemPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void
sender object The sender.
e System.ComponentModel.PropertyChangedEventArgs The instance containing the event data.
return void

OnPropertyObjectPropertyChanged() protected method

Called when a property that implements INotifyPropertyChanged raises the event.
protected OnPropertyObjectPropertyChanged ( object sender, PropertyChangedEventArgs e ) : void
sender object The sender.
e System.ComponentModel.PropertyChangedEventArgs The instance containing the event data.
return void

OnValidated() protected method

Called when the object is validated.
protected OnValidated ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

OnValidatedBusinessRules() protected method

Called when the object has validated the business rules.
protected OnValidatedBusinessRules ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

OnValidatedFields() protected method

Called when the object has validated the fields.
protected OnValidatedFields ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

OnValidating() protected method

Called when the object is validating.
protected OnValidating ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

OnValidatingBusinessRules() protected method

Called when the object is validating the business rules.
protected OnValidatingBusinessRules ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

OnValidatingFields() protected method

Called when the object is validating the fields.
protected OnValidatingFields ( IValidationContext validationContext ) : void
validationContext IValidationContext The validation context.
return void

RaisePropertyChanged() protected method

Raises the INotifyPropertyChanged.PropertyChanged event.
This method is overriden en does not call the base because lots of additional logic is added in this class. The RaisePropertyChanged(object,System.ComponentModel.PropertyChangedEventArgs,bool,bool) will explicitly call ObservableObject.RaisePropertyChanged(object, AdvancedPropertyChangedEventArgs). If this method is overriden, it is very important to call the base.
protected RaisePropertyChanged ( object sender, Catel.Data.AdvancedPropertyChangedEventArgs e ) : void
sender object The sender.
e Catel.Data.AdvancedPropertyChangedEventArgs The instance containing the event data.
return void

SetDirtyAndAutomaticallyValidate() protected method

Sets the IsDirty property and automatically validate if required.
protected SetDirtyAndAutomaticallyValidate ( string propertyName, bool setDirtyAndAllowAutomaticValidation ) : void
propertyName string Name of the property.
setDirtyAndAllowAutomaticValidation bool If set to true, the property is set and automatic validation is allowed.
return void

SetParent() protected method

Sets the new parent of this object.
protected SetParent ( IParent parent ) : void
parent IParent The new parent.
return void

ShouldPropertyChangeUpdateIsDirty() protected method

Determines whether a specific property change should update IsDirty to true.
protected ShouldPropertyChangeUpdateIsDirty ( string propertyName ) : bool
propertyName string
return bool

SuspendChangeCallbacks() public method

Suspends the change callbacks whenever a property has been called. This is very useful when there are expensive property change callbacks registered with a property that need to be temporarily disabled.
public SuspendChangeCallbacks ( ) : IDisposable
return IDisposable

SuspendChangeNotifications() public method

Suspends the change notifications until the disposed object has been released.
public SuspendChangeNotifications ( bool raiseOnResume = true ) : IDisposable
raiseOnResume bool if set to true, the notifications are invoked on resume.
return IDisposable

SuspendValidations() public method

Suspends the validation until the disposable token has been disposed.
public SuspendValidations ( bool validateOnResume = true ) : IDisposable
validateOnResume bool
return IDisposable

ToString() public method

Returns a System.String that represents this instance.
public ToString ( ) : string
return string

Validate() protected method

Validates the current object for field and business rule errors.
To check whether this object contains any errors, use the INotifyDataErrorInfo.HasErrors property.
protected Validate ( bool force = false ) : void
force bool If set to true, a validation is forced. When the validation is not forced, it means /// that when the object is already validated, and no properties have been changed, no validation actually occurs /// since there is no reason for any values to have changed. ///
return void

Validate() public method

Validates the current object for field and business rule errors.
To check whether this object contains any errors, use the INotifyDataErrorInfo.HasErrors property.
public Validate ( bool force, bool validateDataAnnotations ) : void
force bool If set to true, a validation is forced (even if the object knows it is already validated).
validateDataAnnotations bool If set to true, the data annotations will be checked. This value is only used if is set to true.
return void

ValidateBusinessRules() protected method

Validates the business rules of this object. Override this method to enable validation of business rules.
protected ValidateBusinessRules ( List validationResults ) : void
validationResults List The validation results, add additional results to this list.
return void

ValidateFields() protected method

Validates the field values of this object. Override this method to enable validation of field values.
protected ValidateFields ( List validationResults ) : void
validationResults List The validation results, add additional results to this list.
return void

operator() public static method

Implements the operator ==.
public static operator ( ) : bool
return bool

Property Details

IsDirtyProperty public static property

Register the IsDirty property so it is known in the class.
public static PropertyData IsDirtyProperty
return PropertyData

IsReadOnlyProperty public static property

Register the IsReadOnly property so it is known in the class.
public static PropertyData IsReadOnlyProperty
return PropertyData