Today (15th Jan 2010) Scott blogged about the ASP.NET MVC2 model-validation
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
Anyone knows how can someone add validation rules at runtime programmatically ?
"Programmatic Registration" is a similar functionality supported by ValidationAspects
// register lambda syntax validation functions
typeof(User).GetProperty("Name").AddValidation<string>((name, context) =>
{ if (!Exists(name)) { throw new ValidationException("Username is unknown"); } } );
// register validation factories (classes)
typeof(User).GetProperty("Name").AddValidation(new [] { new NotNullOrEmpty()} );
// don't like strings?
TypeOf<User>.Property(user => user.Name).AddValidation(new [] { new NotNullOrEmpty()} );