Tom Hollander在他的Blog介绍了作为下一代企业库(开发代号Enterprise Library v3)中的新成员Validation Application BlockTom Hollander在这里提供了一些实现验证的想法,对于Enterprise Library比较关注的朋友可以一睹为快!

定义验证规则

1.使用配置

沿用Enterprise Library中以前的一贯做法,可以使用Enterprise Library配置工具进行配置验证规则。

2.使用特性

通过加上特性来实现验证,如下面的例子所示:

Enterprise Library v3中的新成员:Validation Application Blockpublic class Customer

3.在代码中验证

某些场景下需要在代码中实现验证

Enterprise Library v3中的新成员:Validation Application BlockIValidator<string> emailAddressValidator = new RegExValidator("xxxx");
Enterprise Library v3中的新成员:Validation Application BlockIValidator
<string> shortStringValidator = new AndCompositeValidator<string>(
Enterprise Library v3中的新成员:Validation Application Block    
new NotNullValidator<string>(), new StringLengthValidator(15));
Enterprise Library v3中的新成员:Validation Application Block

在文章中还介绍了验证对象和创建自己的验证器。

详情可以访问:

http://blogs.msdn.com/tomholl/archive/2006/11/27/validation-application-block-revealed.aspx

相关文章:

  • 2022-01-29
  • 2021-11-24
  • 2021-12-11
  • 2022-01-22
  • 2021-08-31
  • 2021-12-07
猜你喜欢
  • 2021-09-08
  • 2021-07-26
  • 2021-10-18
  • 2022-01-16
  • 2021-12-03
  • 2021-12-07
相关资源
相似解决方案