Created
November 16, 2018 14:01
-
-
Save wellingtonjhn/0dfa933aca1684e6fde0592619b215c6 to your computer and use it in GitHub Desktop.
Entity validation with Exceptions Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Customer | |
| { | |
| public string Name { get; } | |
| public string Email { get; } | |
| public Customer(string name, string email) | |
| { | |
| if (string.IsNullOrEmpty(name)) | |
| { | |
| throw new InvalidOperationException("Name cannot be empty"); | |
| } | |
| if (!email.Contains("@")) | |
| { | |
| throw new InvalidOperationException("Invalid email"); | |
| } | |
| Name = name; | |
| Email = email; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment