Class ObservableObject
A simple lightweight base implementation for System.ComponentModel.INotifyPropertyChanged and System.ComponentModel.IDataErrorInfo
Inheritance
Implements
Namespace: Sartorius.SAF.Infrastructure
Assembly: Sartorius.SAF.dll
Syntax
public abstract class ObservableObject : INotifyPropertyChanged, IDataErrorInfo, INotifyDataErrorInfo, INotifyDataPropertyChanged
Constructors
View SourceObservableObject()
Initializes a new instance of the ObservableObject class.
Declaration
protected ObservableObject()
Properties
View SourceHasErrors
Gets a value indicating whether this entity has validation errors.
Declaration
protected bool HasErrors { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Methods
View SourceAddError(IError)
Adds the specified entity level error.
Declaration
protected bool AddError(IError error)
Parameters
Type | Name | Description |
---|---|---|
IError | error | The entity level error. |
Returns
Type | Description |
---|---|
System.Boolean |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentException | Thrown when |
CascadeErrors()
Cascades errors from property values that implement System.ComponentModel.INotifyDataErrorInfo.
Declaration
protected IDisposable CascadeErrors()
Returns
Type | Description |
---|---|
System.IDisposable | An System.IDisposable that ends cascading when it's System.IDisposable.Dispose() method is called. |
ClearErrors()
Clears all errors.
Declaration
protected void ClearErrors()
ForceValidation<T>(String, T)
Forces the validation for the specified property.
Declaration
protected void ForceValidation<T>(string propertyName, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property being changed. |
T | value | The new value. |
Type Parameters
Name | Description |
---|---|
T | The type of the property value. |
GetEntityErrors()
Gets the current entity level errors.
Declaration
protected virtual IEnumerable<IError> GetEntityErrors()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IError> | An enumerable of all entity level errors. |
GetErrors(String)
Gets the validation errors for a specified property or the entire entity.
Declaration
protected virtual IEnumerable<string> GetErrors(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property to retrieve validation errors for; or |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> | The validation errors for a specified property or the entire entity. |
OnDataPropertyChanged(String)
Called when a data property is changed.
Declaration
protected virtual void OnDataPropertyChanged(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property. |
See Also
View SourceOnErrorsChanged(String)
Raise a System.ComponentModel.INotifyDataErrorInfo.ErrorsChanged event for the specified property.
Declaration
protected virtual void OnErrorsChanged(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property that has it's error state changed. |
OnPropertyChanged(String)
Raise a PropertyChanged event for the given property name.
Declaration
protected virtual void OnPropertyChanged(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property that has changed. |
OnValidate(String)
Called when a property is changed and needs validation.
Declaration
protected virtual string OnValidate(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property to validate. |
Returns
Type | Description |
---|---|
System.String | The description of the error if the property fails validation; |
RemoveError(IError)
Removes the specified entity level error.
Declaration
protected bool RemoveError(IError error)
Parameters
Type | Name | Description |
---|---|---|
IError | error | The entity level error. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
RemoveError(Guid)
Removes the specified entity level error.
Declaration
protected bool RemoveError(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The id of the error to remove. |
Returns
Type | Description |
---|---|
System.Boolean |
|
SetValue<T>(String, ref T, T)
Sets the given value if it is different to the given field using the provided System.Collections.Generic.IEqualityComparer<T>.
This will trigger a validation raise System.ComponentModel.INotifyPropertyChanged.PropertyChanged if field
and value
are not equal.
Declaration
protected void SetValue<T>(string propertyName, ref T field, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property being changed. |
T | field | The field which should hold the property value. |
T | value | The new value. |
Type Parameters
Name | Description |
---|---|
T | The type of the property value. |
SetValue<T>(String, ref T, T, Action<T>, Action<T>)
Sets the given value if it is different to the given field using the provided System.Collections.Generic.IEqualityComparer<T>.
This will trigger a validation raise System.ComponentModel.INotifyPropertyChanged.PropertyChanged if field
and value
are not equal.
Declaration
protected void SetValue<T>(string propertyName, ref T field, T value, Action<T> beforeChange, Action<T> afterChange)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property being changed. |
T | field | The field which should hold the property value. |
T | value | The new value. |
System.Action<T> | beforeChange | An action executed before the |
System.Action<T> | afterChange | An action executed after the |
Type Parameters
Name | Description |
---|---|
T | The type of the property value. |
SetValue<T>(String, ref T, T, Action<T>, Action<T>, IEqualityComparer<T>)
Sets the given value if it is different to the given field using the provided System.Collections.Generic.IEqualityComparer<T>.
This will trigger a validation raise System.ComponentModel.INotifyPropertyChanged.PropertyChanged if field
and value
are not equal.
Declaration
protected virtual void SetValue<T>(string propertyName, ref T field, T value, Action<T> beforeChange, Action<T> afterChange, IEqualityComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property being changed. |
T | field | The field which should hold the property value. |
T | value | The new value. |
System.Action<T> | beforeChange | An action executed before the |
System.Action<T> | afterChange | An action executed after the |
System.Collections.Generic.IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer<T> used to compare the field and the new value. |
Type Parameters
Name | Description |
---|---|
T | The type of the property value. |
SetValue<T>(String, ref T, T, IEqualityComparer<T>)
Sets the given value if it is different to the given field using the provided System.Collections.Generic.IEqualityComparer<T>.
This will trigger a validation raise System.ComponentModel.INotifyPropertyChanged.PropertyChanged if field
and value
are not equal.
Declaration
protected void SetValue<T>(string propertyName, ref T field, T value, IEqualityComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the property being changed. |
T | field | The field which should hold the property value. |
T | value | The new value. |
System.Collections.Generic.IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer<T> used to compare the field and the new value. |
Type Parameters
Name | Description |
---|---|
T | The type of the property value. |
Events
View SourcePropertyChanged
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
System.ComponentModel.PropertyChangedEventHandler |
Explicit Interface Implementations
View SourceINotifyDataPropertyChanged.DataPropertyChanged
Declaration
event EventHandler<PropertyChangedEventArgs> INotifyDataPropertyChanged.DataPropertyChanged
Returns
Type | Description |
---|---|
System.EventHandler<System.ComponentModel.PropertyChangedEventArgs> |
IDataErrorInfo.Error
Declaration
string IDataErrorInfo.Error { get; }
Returns
Type | Description |
---|---|
System.String |
IDataErrorInfo.Item[String]
Declaration
string IDataErrorInfo.this[string columnName] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | columnName |
Returns
Type | Description |
---|---|
System.String |
INotifyDataErrorInfo.ErrorsChanged
Declaration
event EventHandler<DataErrorsChangedEventArgs> INotifyDataErrorInfo.ErrorsChanged
Returns
Type | Description |
---|---|
System.EventHandler<System.ComponentModel.DataErrorsChangedEventArgs> |
INotifyDataErrorInfo.GetErrors(String)
Declaration
IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName |
Returns
Type | Description |
---|---|
System.Collections.IEnumerable |
INotifyDataErrorInfo.HasErrors
Declaration
bool INotifyDataErrorInfo.HasErrors { get; }
Returns
Type | Description |
---|---|
System.Boolean |