我可以使用 DataAnnotations 自定义验证 .NET 中的对象吗?
是否可以在对象上使用 DataAnnotations,然后以编程方式测试该对象是否有效?
我没有使用 MVC3
或 ModelBinding
或 ASP.NET
..而是使用 WinForms
应用程序。
这可能吗?
例如。
if (foo.IsValid) ? Hi() : Bye();
IsValid 以某种方式检查每个具有 DataAnnotations 的属性,或者其他东西。 ??
Is it possible to use DataAnnotations
on an object and then .. programmatically, test to see if that object is Valid
or not?
I'm not using MVC3
or ModelBinding
or ASP.NET
.. but a WinForms
app.
Is this possible?
eg.
if (foo.IsValid) ? Hi() : Bye();
and the IsValid somehow checks each property that has DataAnnotations
on em, or something. ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找
验证器
类。You're looking for the
Validator
class.我知道 SLAks 已经回答了我的问题,但是
I know SLaks has answered my question, but here is another good, detailed description of the solution from Scott Allen :)