有没有办法向验证器提供默认的 MessageTemplateResourceType?
我有一个类,其中有很多需要验证的字符串属性。 我使用验证应用程序块是因为我非常喜欢使用属性来解决此类需求。 一切都很好,但我的经理不喜欢实现消息模板令牌和资源文件所需的代码量。
例如:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仍然可以编写自定义属性。
It is still possible to write custom attribute.