0

I have created Custom validator using Validation Application Block. Its working fine. But how to give design time support for the same validator. I have to use this custom validator in Enterprice Library Configuration Application Console How?

This is Custom Validator Code..

 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class StringIsNullOrEmptyAttribute : ValueValidatorAttribute
{
    protected override Validator DoCreateValidator(Type targetType)
    {
        return new StringIsNullOrEmpty(this.MessageTemplate, this.Negated);
    }
}

public class StringIsNullOrEmpty : ValueValidator<string>
{
    public StringIsNullOrEmpty(string messageTemplate, bool negated)
        : base(messageTemplate, null, negated)
    {
    }

    protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults)
    {
        if (string.IsNullOrEmpty(objectToValidate) != Negated)
        {
            LogValidationResult(validationResults, GetMessage(objectToValidate, key), currentTarget, key);
        }
    }

    protected override string DefaultNegatedMessageTemplate
    {
        get
        {
            return "Field cannot have a value.";
        }
    }

    protected override string DefaultNonNegatedMessageTemplate
    {
        get
        {
            return "Field is required.";
        }
    }
}
Sukesh Chand
  • 2,339
  • 2
  • 21
  • 29

1 Answers1

0

I got the answer from the CodePlex. Here is the link

Design time support for custom validator - Validation Application Block

sukesh chand

Sukesh Chand
  • 2,339
  • 2
  • 21
  • 29