FluentValidation
2016-05-29 21:30
471 查看
git :https://github.com/JeremySkinner/FluentValidation
Example
using FluentValidation; public class CustomerValidator: AbstractValidator<Customer> { public CustomerValidator() { RuleFor(customer => customer.Surname).NotEmpty(); RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name"); RuleFor(customer => customer.Discount).NotEqual(0).When(customer => customer.HasDiscount); RuleFor(customer => customer.Address).Length(20, 250); RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode"); } private bool BeAValidPostcode(string postcode) { // custom postcode validating logic goes here } } Customer customer = new Customer(); CustomerValidator validator = new CustomerValidator(); ValidationResult results = validator.Validate(customer); bool validationSucceeded = results.IsValid; IList<ValidationFailure> failures = results.Errors;
相关文章推荐
- BlockingQueue 实现解析
- 4、在JavaWeb里面,常用的request2Bean的实现
- Hibernate:Caused by: java.sql.SQLException: Incorrect string value: '\xE8\x8F异常
- CruiseControl初探
- 无法点击,无法获取inputvalue值得原因
- LightOJ 1154 - Penguins 最大流
- Git Github jekyll,gem Liquid模板语言 Markdown
- disque基本流程介绍
- 安卓前端 UI框架
- Android---相册getContentResolver().query结果为空指针
- Android UI开发中LayoutParams的应用
- [置顶] Android 6.0 Marshmallow 通知栏中QuickSetting分析
- Java之GUI-------边界布局管理器
- java之GUI-------JButton的使用
- java之GUI-----初涉窗体
- GUI
- iOS AutoLayout: 关联 Xib 和 UIView
- 回溯法——permutation-sequence 返回第k个排序序列
- String、StringBuffer、StringBuilder
- sizeThatFits and sizeToFit是UIView的两个方法