-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Contact.shared.cs
186 lines (163 loc) · 5.54 KB
/
Contact.shared.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.Maui.ApplicationModel.Communication
{
/// <summary>
/// Represents a contact on the user's device.
/// </summary>
public class Contact
{
string displayName;
/// <summary>
/// Initializes a new instance of the <see cref="Contact"/> class.
/// </summary>
public Contact()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Contact"/> class with the given data.
/// </summary>
/// <param name="id">The identifier of the contact.</param>
/// <param name="namePrefix">The prefix of the contact.</param>
/// <param name="givenName">The given name (or first name) of the contact.</param>
/// <param name="middleName">The middle name(s) of the contact.</param>
/// <param name="familyName">The family name (or last name) of the contact.</param>
/// <param name="nameSuffix">The suffix of the contact.</param>
/// <param name="phones">A collection of phone numbers for the contact.</param>
/// <param name="email">A collection of email addresses for the contact.</param>
/// <param name="displayName">The display name of the contact.</param>
public Contact(
string id,
string namePrefix,
string givenName,
string middleName,
string familyName,
string nameSuffix,
IEnumerable<ContactPhone> phones,
IEnumerable<ContactEmail> email,
string displayName = null)
{
Id = id;
NamePrefix = namePrefix;
GivenName = givenName;
MiddleName = middleName;
FamilyName = familyName;
NameSuffix = nameSuffix;
Phones.AddRange(phones?.ToList());
Emails.AddRange(email?.ToList());
DisplayName = displayName;
}
/// <summary>
/// Gets or sets the identifier of the contact.
/// </summary>
public string Id { get; set; }
/// <summary>
/// Gets or sets the display name of the contact.
/// </summary>
/// <remarks>If no display name is set, a display name is inferred from <see cref="GivenName"/> and <see cref="FamilyName"/>.</remarks>
public string DisplayName
{
get => !string.IsNullOrWhiteSpace(displayName) ? displayName : BuildDisplayName();
private set => displayName = value;
}
/// <summary>
/// Gets or sets the name prefix of the contact.
/// </summary>
public string NamePrefix { get; set; }
/// <summary>
/// Gets or sets the given name (or first name) of the contact.
/// </summary>
public string GivenName { get; set; }
/// <summary>
/// Gets or sets the middle name(s) of the contact.
/// </summary>
public string MiddleName { get; set; }
/// <summary>
/// Gets or sets the family name (or last name) of the contact.
/// </summary>
public string FamilyName { get; set; }
/// <summary>
/// Gets or sets the name suffix of the contact.
/// </summary>
public string NameSuffix { get; set; }
/// <summary>
/// Gets or sets a collection of phone numbers of the contact.
/// </summary>
public List<ContactPhone> Phones { get; set; } = new List<ContactPhone>();
/// <summary>
/// Gets or sets a collection of email addresses of the contact.
/// </summary>
public List<ContactEmail> Emails { get; set; } = new List<ContactEmail>();
/// <summary>
/// Returns a string representation of the current values of <see cref="Contact"/>.
/// </summary>
/// <returns>A string representation of this instance. The return value is the current value of <see cref="DisplayName"/>.</returns>
public override string ToString() => DisplayName;
string BuildDisplayName()
{
if (string.IsNullOrWhiteSpace(GivenName))
return FamilyName;
if (string.IsNullOrWhiteSpace(FamilyName))
return GivenName;
return $"{GivenName} {FamilyName}";
}
}
/// <summary>
/// Represents an email address that is associated with a <see cref="Contact"/>.
/// </summary>
public class ContactEmail
{
/// <summary>
/// Initializes a new instance of the <see cref="ContactEmail"/> class.
/// </summary>
public ContactEmail()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ContactEmail"/> class with the given data.
/// </summary>
/// <param name="emailAddress">The email address.</param>
public ContactEmail(string emailAddress)
{
EmailAddress = emailAddress;
}
/// <summary>
/// Gets or sets the email address.
/// </summary>
public string EmailAddress { get; set; }
/// <summary>
/// Returns a string representation of the current values of <see cref="Contact"/>.
/// </summary>
/// <returns>A string representation of this instance. The return value is the current value of <see cref="EmailAddress"/>.</returns>
public override string ToString() => EmailAddress;
}
/// <summary>
/// Represents a phone number that is associated with a <see cref="Contact"/>.
/// </summary>
public class ContactPhone
{
/// <summary>
/// Initializes a new instance of the <see cref="ContactPhone"/> class.
/// </summary>
public ContactPhone()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ContactPhone"/> class with the given data.
/// </summary>
/// <param name="phoneNumber">The phone number.</param>
public ContactPhone(string phoneNumber)
{
PhoneNumber = phoneNumber;
}
/// <summary>
/// Gets or sets the phone number.
/// </summary>
public string PhoneNumber { get; set; }
/// <summary>
/// Returns a string representation of the current values of <see cref="Contact"/>.
/// </summary>
/// <returns>A string representation of this instance. The return value is the current value of <see cref="PhoneNumber"/>.</returns>
public override string ToString() => PhoneNumber;
}
}