microsoft/TypeAgent
Publicmirrored from https://github.com/microsoft/TypeAgentAvailable
dotnet/email/EmailAddress.cs
52lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | namespace TypeAgent; |
| 5 | |
| 6 | public class EmailAddress |
| 7 | { |
| 8 | public EmailAddress() |
| 9 | { |
| 10 | } |
| 11 | |
| 12 | public EmailAddress(string address, string displayName = null) |
| 13 | { |
| 14 | Address = address; |
| 15 | DisplayName = displayName; |
| 16 | } |
| 17 | |
| 18 | [JsonPropertyName("address")] |
| 19 | public string Address { get; set; } |
| 20 | [JsonPropertyName("displayName")] |
| 21 | public string DisplayName { get; set; } |
| 22 | |
| 23 | public override string ToString() |
| 24 | { |
| 25 | if (string.IsNullOrEmpty(DisplayName)) |
| 26 | { |
| 27 | return Address ?? string.Empty; |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | return string.IsNullOrEmpty(Address) ? DisplayName : $"\"{DisplayName}\" <{Address}>"; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public static class EmailAddressEx |
| 37 | { |
| 38 | public static string Join(this List<EmailAddress> list) |
| 39 | { |
| 40 | StringBuilder sb = new StringBuilder(); |
| 41 | for (int i = 0; i < list.Count; ++i) |
| 42 | { |
| 43 | var item = list[i]; |
| 44 | if (i > 0) |
| 45 | { |
| 46 | sb.Append(", "); |
| 47 | } |
| 48 | sb.Append(item.ToString()); |
| 49 | } |
| 50 | return sb.ToString(); |
| 51 | } |
| 52 | } |
| 53 | |