Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. namespace EfAndCpf
  2. {
  3. public class Email
  4. {
  5. public string EmailValue { get; private set; }
  6.  
  7. private Email()
  8. {
  9.  
  10. }
  11.  
  12. private Email(string value)
  13. {
  14. EmailValue = value;
  15. }
  16.  
  17. public static implicit operator Email(string value)
  18. => Parse(value);
  19.  
  20. public static implicit operator string(Email email)
  21. => email.EmailValue;
  22.  
  23. public static Email Parse(string value)
  24. {
  25. // ... validations here
  26. // throwing exceptions if something goes wrong.
  27.  
  28. return new Email(value);
  29. }
  30.  
  31. public bool IsEmpty => EmailValue == null;
  32.  
  33. public override string ToString()
  34. => EmailValue;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement