C# Class Mvvm.BindableValidator

The BindableValidator class run validation rules of an entity, and stores a collection of errors of the properties that did not pass validation. The validation is run on each property change or whenever the ValidateProperties method is called. It also provides an indexer property, that uses the property names as keys and return the error list for the specified property.
Inheritance: INotifyPropertyChanged
Datei anzeigen Open project: XamlBrewer/UWP-Prism-Validation-Sample

Public Properties

Property Type Description
EmptyErrorsCollection ReadOnlyCollection

Public Methods

Method Description
BindableValidator ( INotifyPropertyChanged entityToValidate ) : System

Initializes a new instance of the BindableValidator class with the entity to validate.

BindableValidator ( INotifyPropertyChanged entityToValidate, Func getResourceDelegate ) : System

Initializes a new instance of the BindableValidator class with the entity to validate.

GetAllErrors ( ) : ReadOnlyCollection>.ReadOnlyDictionary

Returns a new ReadOnlyDictionary containing all the errors of the Entity, separated by property.

SetAllErrors ( IDictionary entityErrors ) : void

Updates the errors collection of the entity, notifying if the errors collection has changed.

ValidateProperties ( ) : bool

Validates all the properties decorated with the ValidationAttribute attribute. It updates each property errors collection with the new validation results (notifying if necessary).

ValidateProperty ( string propertyName ) : bool

Validates the property, based on the rules set in the property ValidationAttributes attributes. It updates the errors collection with the new validation results (notifying if necessary).

this ( string propertyName ) : ReadOnlyCollection

Returns the errors of the property.

Private Methods

Method Description
OnErrorsChanged ( string propertyName ) : void

Notifies listeners that the errors of a property have changed.

OnPropertyChanged ( string propertyName ) : void

Notifies listeners that a property value has changed.

SetPropertyErrors ( string propertyName, IList propertyNewErrors ) : bool

Updates the errors collection of the property.

TryValidateProperty ( PropertyInfo propertyInfo, List propertyErrors ) : bool

Performs a validation of a property, adding the results in the propertyErrors list.

Method Details

BindableValidator() public method

Initializes a new instance of the BindableValidator class with the entity to validate.
When is .
public BindableValidator ( INotifyPropertyChanged entityToValidate ) : System
entityToValidate INotifyPropertyChanged The entity to validate
return System

BindableValidator() public method

Initializes a new instance of the BindableValidator class with the entity to validate.
When is .
public BindableValidator ( INotifyPropertyChanged entityToValidate, Func getResourceDelegate ) : System
entityToValidate INotifyPropertyChanged The entity to validate
getResourceDelegate Func A delegate that returns a string resource given a resource map Id and resource Id
return System

GetAllErrors() public method

Returns a new ReadOnlyDictionary containing all the errors of the Entity, separated by property.
public GetAllErrors ( ) : ReadOnlyCollection>.ReadOnlyDictionary
return ReadOnlyCollection>.ReadOnlyDictionary

SetAllErrors() public method

Updates the errors collection of the entity, notifying if the errors collection has changed.
public SetAllErrors ( IDictionary entityErrors ) : void
entityErrors IDictionary The collection of errors for the entity.
return void

ValidateProperties() public method

Validates all the properties decorated with the ValidationAttribute attribute. It updates each property errors collection with the new validation results (notifying if necessary).
public ValidateProperties ( ) : bool
return bool

ValidateProperty() public method

Validates the property, based on the rules set in the property ValidationAttributes attributes. It updates the errors collection with the new validation results (notifying if necessary).
When is or an empty string value. When the parameter does not match any property name.
public ValidateProperty ( string propertyName ) : bool
propertyName string The name of the property to validate.
return bool

this() public method

Returns the errors of the property.
public this ( string propertyName ) : ReadOnlyCollection
propertyName string The name of the property.
return ReadOnlyCollection

Property Details

EmptyErrorsCollection public_oe static_oe property

Represents a collection of empty error values.
public static ReadOnlyCollection EmptyErrorsCollection
return ReadOnlyCollection