using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Stylet { /// /// Generic version of IValidationArapter. Provided for use with StyletIoC /// /// /// Having a generic version allows you implement it using a generic ModelValidator (ModelValidator{T} : IModelValidator{T}) /// then write a binding rule like this: /// builder.Bind(typeof(IModelValidator{})).ToAllImplementations() /// and request a new IModelValidator{MyViewModelType} in your ViewModel's constructor. /// /// Type of model being validated // ReSharper disable once UnusedTypeParameter public interface IModelValidator : IModelValidator { } /// /// Adapter used by ValidationModelBase to perform validation. /// /// /// This should be specialised to the particular ValidationModelBase instance it's validating /// public interface IModelValidator { /// /// Called by ValidatingModelBase, which passes in an instance of itself. /// This allows the IModelValidator to specialize to validating that particular ValidatingModelBase instance /// /// Subject to initialize void Initialize(object subject); /// /// Validate a single property by name, and return an array of validation errors for that property (or null if validation was successful) /// /// Property to validate, or to validate the entire model /// Array of validation errors, or null / empty if validation was successful Task> ValidatePropertyAsync(string propertyName); /// /// Validate all properties, and return the results for all properties /// /// /// Use a key of to indicate validation errors for the entire model. /// /// If a property validates successfully, you MUST return a null entry for it in the returned dictionary! /// /// A dictionary of property name => array of validation errors (or null if that property validated successfully) Task>> ValidateAllPropertiesAsync(); } }