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.";
}
}
}