Pure.Krome
Pure.Krome

Reputation: 86957

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?

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. ??

Upvotes: 1

Views: 114

Answers (2)

Pure.Krome
Pure.Krome

Reputation: 86957

I know SLaks has answered my question, but here is another good, detailed description of the solution from Scott Allen :)

Upvotes: 0

SLaks
SLaks

Reputation: 887453

You're looking for the Validator class.

Upvotes: 3

Related Questions