ValidatorBase.cs 885 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.ComponentModel;
  2. namespace OpenSEMI.ClientBase
  3. {
  4. public abstract class ValidatorBase
  5. : IDataErrorInfo
  6. {
  7. private DataErrorInfo<ValidatorBase> DataErrorValidator;
  8. #region Implementation of IDataErrorInfo
  9. public string this[string propertyName]
  10. {
  11. get { return GetDataErrorInfo()[propertyName]; }
  12. }
  13. public string Error
  14. {
  15. get { return GetDataErrorInfo().Error; }
  16. }
  17. #endregion
  18. public bool IsValid
  19. {
  20. get { return string.IsNullOrEmpty(Error); }
  21. }
  22. private DataErrorInfo<ValidatorBase> GetDataErrorInfo()
  23. {
  24. if (DataErrorValidator != null) return DataErrorValidator;
  25. DataErrorValidator = new DataErrorInfo<ValidatorBase>(this);
  26. return DataErrorValidator;
  27. }
  28. }
  29. }