【问题标题】:Design time support for custom validator in Microsoft Validation Application BlockMicrosoft 验证应用程序块中自定义验证器的设计时支持
【发布时间】:2013-04-15 18:52:11
【问题描述】:

我使用验证应用程序块创建了自定义验证器。它工作正常。 但是如何为同一个验证器提供设计时支持。我必须在 Enterprice 库配置应用程序控制台中使用此自定义验证器 怎么样?

这是自定义验证器代码..

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

【问题讨论】:

    标签: c# .net validation enterprise-library


    【解决方案1】:

    我从 CodePlex 得到了答案。这是链接

    Design time support for custom validator - Validation Application Block

    苏克什·钱德

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      相关资源
      最近更新 更多