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.

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