Class ObservableObject
A simple lightweight base implementation for INotifyPropertyChanged and IDataErrorInfo
Inheritance
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 |
|---|---|
| bool |
|
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 |
|---|---|
| bool |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentException | Thrown when |
CascadeErrors()
Cascades errors from property values that implement INotifyDataErrorInfo.
Declaration
protected IDisposable CascadeErrors()
Returns
| Type | Description |
|---|---|
| IDisposable | An IDisposable that ends cascading when it's 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 |
|---|---|---|
| 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 |
|---|---|
| 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 |
|---|---|---|
| string | propertyName | The name of the property to retrieve validation errors for; or |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|---|
| string | propertyName | The name of the property. |
See Also
View SourceOnErrorsChanged(string)
Raise a ErrorsChanged event for the specified property.
Declaration
protected virtual void OnErrorsChanged(string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| 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 |
|---|---|---|
| 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 |
|---|---|---|
| string | propertyName | The name of the property to validate. |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
RemoveError(Guid)
Removes the specified entity level error.
Declaration
protected bool RemoveError(Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The id of the error to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
SetValue<T>(string, ref T, T)
Sets the given value if it is different to the given field using the provided IEqualityComparer<T>.
This will trigger a validation raise PropertyChanged if field and value are not equal.
Declaration
protected void SetValue<T>(string propertyName, ref T field, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| 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 IEqualityComparer<T>.
This will trigger a validation raise 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 |
|---|---|---|
| string | propertyName | The name of the property being changed. |
| T | field | The field which should hold the property value. |
| T | value | The new value. |
| Action<T> | beforeChange | An action executed before the |
| 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 IEqualityComparer<T>.
This will trigger a validation raise 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 |
|---|---|---|
| string | propertyName | The name of the property being changed. |
| T | field | The field which should hold the property value. |
| T | value | The new value. |
| Action<T> | beforeChange | An action executed before the |
| Action<T> | afterChange | An action executed after the |
| IEqualityComparer<T> | comparer | The 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 IEqualityComparer<T>.
This will trigger a validation raise 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 |
|---|---|---|
| string | propertyName | The name of the property being changed. |
| T | field | The field which should hold the property value. |
| T | value | The new value. |
| IEqualityComparer<T> | comparer | The 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
Occurs when a property value changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
| Type | Description |
|---|---|
| PropertyChangedEventHandler |