EntLib 的多种验证方案 - .resx 样式?

发布于 2024-08-21 05:14:17 字数 172 浏览 4 评论 0原文

目前,我在我的类中定义了一组 EntLib 验证规则。规则稍后将根据客户而变化。

我想做的是保留我的类,并简单地调用为特定客户端定义的不同规则集。

其功能类似于在 .resx 文件中存储国际化值,其中内容根据本地化参数而变化,但在这种情况下,预定义的规则将根据客户端而变化。

谢谢。

Currently I've got a set of EntLib validation rules defined in my classes. The rules will later change based on the client.

What I'd like to do is retain my classes, and simply call the different rule sets defined somewhere for the specific client.

The functionality of this is similar to storing internationalization values in a .resx file, where content changes based on localization parameters, but in this case, the pre-defined rules would change based on the client.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天冷不及心凉 2024-08-28 05:14:17

对于那些想知道的人,给定 TerminalId 参数的以下规则集:

<ValidatorComposition(CompositionType.And)> _
<NotNullValidator(MessageTemplate:="Terminal id is required.", Ruleset:="Default")> _
<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Default")> _
Public Property TerminalId() As String
    Get
        Return _TerminalId
    End Get
    Set(ByVal value As String)
        _TerminalId = value
    End Set
End Property

只需添加额外的规则集标识符即可解决问题。

<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Client1.Default")>
<StringLengthValidator(3, 10, MessageTemplate:="Terminal id must be between 3 and 10 digits in length.", Ruleset:="Client2.Default")>
<StringLengthValidator(5, 25, MessageTemplate:="Terminal id must be between 5 and 25 digits in length.", Ruleset:="Client3.Default")>

...然后只需调用与登录客户端匹配的适当验证规则集。

啊EntLib。

For those who wonder, given the following ruleset for a TerminalId parameter:

<ValidatorComposition(CompositionType.And)> _
<NotNullValidator(MessageTemplate:="Terminal id is required.", Ruleset:="Default")> _
<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Default")> _
Public Property TerminalId() As String
    Get
        Return _TerminalId
    End Get
    Set(ByVal value As String)
        _TerminalId = value
    End Set
End Property

Simply adding an additional rule set identifier would do the trick.

<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Client1.Default")>
<StringLengthValidator(3, 10, MessageTemplate:="Terminal id must be between 3 and 10 digits in length.", Ruleset:="Client2.Default")>
<StringLengthValidator(5, 25, MessageTemplate:="Terminal id must be between 5 and 25 digits in length.", Ruleset:="Client3.Default")>

... then simply calling the appropriate validation rule set that matches the logged-in client.

Ah EntLib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文