views:

68

answers:

1

Hello,

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
A: 

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

http://stackoverflow.com/questions/2112143/how-can-i-define-a-idataerrorinfo-error-property-for-multiple-bo-properties/2130916#2130916

adrianm
That way I have to use another library right? I do not want that...
msfanboy
and... I would also have to annotate every stringempty and max50chars rule to every property...
msfanboy