Enterprise Library v3中的新成员:Validation Application Block

本文介绍了EnterpriseLibrary v3中的验证应用模块,包括使用配置、特性及代码实现验证的方法,并提供了创建自定义验证器的指南。

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

定义验证规则

1.使用配置

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

2.使用特性

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

None.gif public   class  Customer
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
// Using fields instead of properties for brevity
InBlock.gif
[NotNullValidator]
InBlock.gif
InBlock.gif    [StringLengthValidator(
150)]
InBlock.gif    
public string Name;
InBlock.gif
InBlock.gif    [RelativeDateValidator(RelativeDateKind.Before, OffSetFromNow
=0)]
InBlock.gif    
public DateTime DateJoined;
ExpandedBlockEnd.gif}

None.gif

3.在代码中验证

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

None.gif IValidator < string >  emailAddressValidator  =   new  RegExValidator( " xxxx " );
None.gifIValidator
< string >  shortStringValidator  =   new  AndCompositeValidator < string > (
None.gif    
new  NotNullValidator < string > (),  new  StringLengthValidator( 1 5 ));
None.gif

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

详情可以访问:

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

转载于:https://www.cnblogs.com/Terrylee/archive/2006/11/28/Enterprise_Library_v3_Validation_Application_Block.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值