Fluent Validation For .NET
2014-09-27 12:48
169 查看
//.net 中数据验证,一个开源的项目,直接下载 1 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;
相关文章推荐
- Fluent Validation For .net
- asp.net mvc FluentValidation客户端验证失效
- Fluent API for .NET RIA Services Metadata(Reproduced)
- C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation
- asp.net mvc FluentValidation 的使用
- Delphi8 for .net 的 VCL 类库
- 不错的工具:Reflector for .NET
- my new Article In Csdn, only For .net Starter
- NScript - A script host for C#/VB.NET/JScript.NET
- Retrieve multiple Oracle Ref Cursor using .NET data Provider for Oracle
- Delphi 8 for .net 第一时间 之 分析篇
- 在HTML页面中实现点击数统计 For ASP.Net版! (接近正解)
- Build Tools for .NET Applications
- DynamicPorxy for .NET
- 在HTML页面中实现点击数统计 For ASP.Net版! (费事版)
- mono (.NET for Linux) 0.25发布及其横向评测
- Object-Relational Persistence for .NET
- Delphi 8中文帮助-Delphi 8 for .NET是什么?
- Delphi 8 for .net 第一时间 之 预览篇
- Is VS.NET ready for enterprise? (6)