Configuration File mode for Enterprise Library Verification Application Module:
1. Create a console application and create a customer class. The Code is as follows:
Code
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using Microsoft. Practices. enterpriselibrary. validation. validators;
Using Microsoft. Practices. enterpriselibrary. validation;
Namespace consoleapplication1
{
Class Program
{
Staticvoid main (string [] ARGs)
{
}
Publicclass customer
{
Publicstring customername;
Public customer (string customername)
{
This. customername = customername;
}
Publicint test ()
{
Return-5;
}
}
}
2. Run entlibconfig.exe and selectBlocksMenu, clickAdd validation settings.
3. ClickValidated typesClick the plus sign in the upper-right corner of the block, and then clickAdd type to validateIn this case, you need to select the class to be verified, because we want to verify the attributes of the customer class, so we need to import the class we just created, click andAdd from FileFind the leleapplication1.exe under the debug folder of our application program (which varies with the name you created). The customer class is included in this program:
4.
After the import, we can see that there is an consoleapplication1 assembly, and then we want to select the customer class it contains, as shown in, and click OK:
5.
On the customer panel, right-click-add validation ruleset:
6.
In the defaule ruleset attribute on the set customer panel, right-click the newly created validation ruleset attribute on the validation ruleset panel-select members, and select
7.
On the pop-up member selection page, select the test method and customername attribute to be tested:
8.
Right-click the field: mermername panel and choose "add validators-add not ".
Null validator:
9.
Shows the settings for the validator:
10. Right-click the method: Test Panel and choose add validators-add range.
Validator:
11. The settings for this validator are shown in:
12. ClickFileMenu, clickSave, Save asApp. configFile, you can save it to the desktop first, and then use it.
13. Add app. config to the project and add the required references ,:
14. test:
Code
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using Microsoft. Practices. enterpriselibrary. validation. validators;
Using Microsoft. Practices. enterpriselibrary. validation;
Namespace consoleapplication1
{
Class Program
{
Staticvoid main (string [] ARGs)
{
Validator <customer> customervalidator = validationfactory. createvalidator <customer> ("validation ruleset ");
Customer mycustomer = new customer (null );
Validationresults r = customervalidator. Validate (mycustomer );
If (! R. isvalid)
{
For (INT I = 0; I <R. Count; I ++)
{
Console. writeline ("error {0}:" + R. elementat (I). Message, I + 1 );
}
}
Else
{
Console. writeline ("correct ");
}
}
}
Publicclass customer
{
Publicstring customername;
Public customer (string customername)
{
This. customername = customername;
}
Publicint test ()
{
Return-5;
}
}
}
15. Running result:
Demo Download \ ( ̄ []  ̄ \)