例子:
public class UserValidator : AbstractValidator<UserViewModel>
{
public UserValidator()
{
RuleFor(p => p.Username).NotEmpty()
.WithMessage("Please enter a username.");
}
}
public class UserController : ApiController
{
public IHttpActionResult Create(UserViewModel vewModel)
{
if (ModelState.IsValid)
{
return Ok();
}
return BadRequest();
}
}
仅仅通过提供 UserController.Create() 方法和 UserViewModel 对象,如何获取 UserValidator 对象或类型?