You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

4 years ago
  1. using Apewer;
  2. using Apewer.Source;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Apewer.Network
  7. {
  8. /// <summary>邮件地址。</summary>
  9. [Table("_mail_address")]
  10. [Serializable]
  11. public sealed class MailAddress : Record
  12. {
  13. [NonSerialized]
  14. private TextSet _ts = new TextSet(true);
  15. /// <summary>邮件地址。</summary>
  16. [Column]
  17. public string Address { get { return _ts["Address"]; } set { _ts["Address "] = value; } }
  18. /// <summary>名称。</summary>
  19. [Column]
  20. public string Name { get { return _ts["Name"]; } set { _ts["Name "] = value; } }
  21. /// <summary>空记录。</summary>
  22. public MailAddress() { }
  23. /// <summary>收件人。</summary>
  24. /// <param name="address">邮件地址。</param>
  25. public MailAddress(string address)
  26. {
  27. Address = address;
  28. }
  29. /// <summary>收件人。</summary>
  30. /// <param name="address">邮件地址。</param>
  31. /// <param name="name">名称。</param>
  32. public MailAddress(string address, string name)
  33. {
  34. Address = address;
  35. Name = name;
  36. }
  37. /// <summary>获取 JSON 文本。</summary>
  38. public new string ToString()
  39. {
  40. return Json.From(this).ToString();
  41. }
  42. /// <exception cref="ArgumentException"></exception>
  43. /// <exception cref="ArgumentNullException"></exception>
  44. /// <exception cref="InvalidOperationException"></exception>
  45. internal System.Net.Mail.MailAddress ToInstance(Encoding encoding)
  46. {
  47. if (TextUtility.IsBlank(Address)) return null;
  48. var name = TextUtility.IsBlank(Name) ? null : Name;
  49. return new System.Net.Mail.MailAddress(Address, name, encoding);
  50. }
  51. }
  52. }