I have a class called User and a property Name
User
Name
public class User { [Required] public string Name { get; set; } }
You can use Validator to accomplish this.
var context = new ValidationContext(u, serviceProvider: null, items: null); var validationResults = new List(); bool isValid = Validator.TryValidateObject(u, context, validationResults, true);