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. ??
您正在寻找Validator
类 。
我知道SLaks已经回答了我的问题,但这是 Scott Allen 对解决方案的另一个很好的详细说明 :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.