我可以使用DataAnnotations自定义验证.NET中的对象吗?

时间:2011-11-24 01:25:09

标签: c# .net data-annotations

是否可以在对象上使用DataAnnotations然后以编程方式测试该对象是否为Valid

我没有使用MVC3ModelBindingASP.NET ..而是使用WinForms应用。

这可能吗?

例如

if (foo.IsValid) ? Hi() : Bye();

并且IsValid以某种方式检查每个在em上有DataAnnotations的属性。 ??

2 个答案:

答案 0 :(得分:3)

您正在寻找Validator class

答案 1 :(得分:0)

我知道SLaks回答了我的问题,但来自Scott Allen的here is another good, detailed description of the solution:)