有没有办法向验证器提供默认的 MessageTemplateResourceType?

发布于 2024-07-21 10:48:56 字数 514 浏览 10 评论 0原文

我有一个类,其中有很多需要验证的字符串属性。 我使用验证应用程序块是因为我非常喜欢使用属性来解决此类需求。 一切都很好,但我的经理不喜欢实现消息模板令牌和资源文件所需的代码量。

例如:

 [StringLengthValidator(100, 
        MessageTemplateResourceName = "InvalidStringLengthMessage", 
        MessageTemplateResourceType = typeof(Xltech.Common.Resources.XLStrings))]
 public string FirstName {get; set;}

问题是,对于此类中的每个 StringLengthValidator(实际上,对于整个解决方案),100(最大字符串长度)之后的每个参数都是相同的。

有没有办法至少为验证器提供一个通用的 MessageTemplateResourceType,以便我可以减少涉及的复制/粘贴?

I have a class with lots of string properties that need validated. I'm using the Validation Application Block because I'm a big fan of using attributes to solve this kind of need. Everything works great but my manager isn't a fan of the amount of code needed in implementing the Message Template Tokens and resource file.

For example:

 [StringLengthValidator(100, 
        MessageTemplateResourceName = "InvalidStringLengthMessage", 
        MessageTemplateResourceType = typeof(Xltech.Common.Resources.XLStrings))]
 public string FirstName {get; set;}

The issue is that every argument after the 100 (the maximum string length) is the same for every StringLengthValidator we have in this class (actually, for the entire solution).

Is there a way to at least give the validators a common MessageTemplateResourceType so I can reduce the copy/pasting involved?

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

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

发布评论

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

评论(1

眼泪也成诗 2024-07-28 10:48:56

仍然可以编写自定义属性。

It is still possible to write custom attribute.

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