Environment:
Windows 2008, VS 2008 SP1, asp.net MVC 1.0
------------------------------------------------------------------------------
Tea watching tonight, the mind suddenly flashed a thought, so open vs simple to do a realization, so with this article ... It's about entity validation, well, let's start from scratch.
A. Probably the most original validation code
To make the problem as simple as possible, let's take a user class that is simply not easy to use.
Now we're going to add a method to the user class to verify the legality of the user instance, and I believe a lot of people wrote the following code like this:
The Check () method simply applies a variety of rules to the properties of the user class, and then returns an illegal set of hints.
Validation is just a simple call to the entity check () method:
Well, I admit, it seems to be enough in general, but many people see a series of if may start to freak out, yes, I don't like it, then think of the most even way to eliminate them.