-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the ValidateMe wiki!
ValidateMe is a domain validation lib. You can use it just to validate some variables or model's properties or you can even receive some user friendly error messages as well.
It was built as an extension lib to types like int, short, long, DateTime, string, TimeSpan, double and float.
It is simple to use. ValidateMe has two kinds of validation, the simple check returning a bool whether the test passes or the notification validation. In the latter you tells ValidateMe to ensure that your field is something you want it to be.
You can put it inside your setter. For example, if you want you domain's string property to has some value and be greater than 10 characters length, you will do it as follows:
Validator.SetValidations(() =>
{
value
.MustHasValue()
.MustBeGreaterThan(10);
});
/* You can pass a custom name to validations, so the notification message will use it instead the raw property name */
Validator.SetValidations((name) =>
{
name = "Friendly-user name";
value
.MustHasValue(name)
.MustBeGreaterThan(10, name);
});
if (this.CheckValidations())
_name = value;
Inside Validator.SetValidations() all validations will be set. Then, when you need to check if the value matches all the requisites to be valid, all you need to do is call this.CheckValidations(). Using ValidateMe like this will generate a single error message for each validation that fails.
Besides domain validation. You can simply use ValidateMe to check some variables values. As said before, ValidateMe is just an extension library. All "Is" prefixed methods returns bool values telling whether the validation has passed. So, if you want to check if some variable matches some kind of validation, you can use it in a simple conditional check as follows:
`string email = "[email protected]";
if (email.IsEmail()) {
//do something with valid email...
} else {
//do something with invalid email...
}
`
Just to finish, you can add ValidateMe on your application by installing it from nuget.org.
Please feel free to send messages to make the library better. Any help will be appreciated.
You can find me at [email protected]
Sorry for any english mistakes.