0

I have a pupil entity implementing IDataErrorInfo:

Now the exact same rules I want to validate against the Lastname, Gender, Street, City, Postal and Phone.

Do I really have to repeat all that ? Using ValidationRule class would be better but then I

can not handle disabling/enabling buttons via ICommand.

...

 #region Validation Rules

    private string ValidateFirstName()
    {
        if (IsStringMissing(this.FirstName))
            return ErrorStrings.General_Error_StringMustNotBeEmpty;

        if (IsStringTooLong(this.FirstName))
            return ErrorStrings.General_Error_StringTooLong50Maximum;

        return null;
    }

    private static bool IsStringMissing(string value)
    {
        return String.IsNullOrEmpty(value) || value.Trim() == String.Empty;
    }

    private static bool IsStringTooLong(string value)
    {
        return value.Length > 50;
    }

    #endregion
msfanboy
  • 5,273
  • 13
  • 69
  • 120

1 Answers1

0

I think it is easier to use attributes. Look at my answer to this question:

How can I define a IDataErrorInfo Error Property for multiple BO properties

Community
  • 1
  • 1
adrianm
  • 14,468
  • 5
  • 55
  • 102