[英]Can I use DataAnnotations to custom validate an object in .NET?
Is it possible to use DataAnnotations
on an object and then .. programmatically, test to see if that object is Valid
or not? 是否可以在对象上使用
DataAnnotations
然后以编程方式测试该对象是否Valid
?
I'm not using MVC3
or ModelBinding
or ASP.NET
.. but a WinForms
app. 我没有使用
MVC3
或ModelBinding
或ASP.NET
..而是一个WinForms
应用程序。
Is this possible? 这可能吗?
eg. 例如。
if (foo.IsValid) ? Hi() : Bye();
and the IsValid somehow checks each property that has DataAnnotations
on em, or something. 并且IsValid以某种方式检查每个在em上具有
DataAnnotations
属性。 ?? ??
您正在寻找Validator
类 。
我知道SLaks已经回答了我的问题,但这是 Scott Allen 对解决方案的另一个很好的详细说明 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.