NHibernate Validator - 传递资源管理器和密钥

时间:2009-10-13 14:34:35

标签: c# .net validation nhibernate-validator

根据NHibernate Validator文档:

http://nhforge.org/wikis/validator/nhibernate-validator-1-0-0-documentation.aspx

我应该能够通过我的资源管理器,以便将其用于验证错误消息。参见:

  

或者,您可以在以编程方式检查验证规则时提供ResourceManager ...

  

如果NHibernate Validator无法从ResourceManager或ValidatorMessage解析密钥,则它会回退到默认的内置值。

它甚至显示了在实体属性的属性中执行此操作的示例:

 // a not null numeric string of 5 characters maximum
    // if the string is longer, the message will
    // be searched in the resource bundle at key 'long'
    [Length(Max = 5, Message = "{long}")]
    [Pattern(Regex = "[0-9]+")]
    [NotNull]
    public string Zip
    {

        get { return zip; }
        set { zip = value; }
    }

但是,据我所知,它没有说明如何将资源管理器传递给验证框架 - 有谁知道如何做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

查看this postthis SO question的答案(它描述了使用消息插补器时的一些问题)。

希望这会对你有所帮助。