Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wellingtonjhn/0dfa933aca1684e6fde0592619b215c6 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/0dfa933aca1684e6fde0592619b215c6 to your computer and use it in GitHub Desktop.
Entity validation with Exceptions Sample
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