Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For(@object) throws exception when null #176

Open
brunomartinspro opened this issue Jan 2, 2020 · 0 comments
Open

For(@object) throws exception when null #176

brunomartinspro opened this issue Jan 2, 2020 · 0 comments

Comments

@brunomartinspro
Copy link

The for option should have a handled output with an error message, optionally a custom error message would be awesome.

   void ValidateModel(RegisterModel model)
        {
            //Force exception
            model = null;
            var result = ValitRules<RegisterModel>
                .Create()
                .Ensure(m => m.Email, _=>_
                    .Required()
                    .Email())
                .Ensure(m => m.Password, _=>_ 
                    .Required()
                    .MinLength(10))
                .Ensure(m => m.Age, _=>_
                    .IsGreaterThan(16))
                .For(model)
                .Validate();

            if(result.Succeeded)
            {
                // do something on success
            }
            else 
            {
                // do something on failure
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant