-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Contacts.shared.cs
58 lines (51 loc) · 2.09 KB
/
Contacts.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
#nullable enable
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Maui.ApplicationModel.Communication
{
/// <summary>
/// The Contacts API lets a user pick a contact and retrieve information about it.
/// </summary>
public interface IContacts
{
/// <summary>
/// Opens the operating system's default UI for picking a contact from the device.
/// </summary>
/// <returns>A single contact, or <see langword="null"/> if the user cancelled the operation.</returns>
Task<Contact?> PickContactAsync();
/// <summary>
/// Gets a collection of all the contacts on the device.
/// </summary>
/// <param name="cancellationToken">A token that can be used for cancelling the operation.</param>
/// <returns>A collection of contacts on the device.</returns>
Task<IEnumerable<Contact>> GetAllAsync(CancellationToken cancellationToken = default);
}
/// <summary>
/// The Contacts API lets a user pick a contact and retrieve information about it.
/// </summary>
public static class Contacts
{
/// <summary>
/// Opens the operating system's default UI for picking a contact from the device.
/// </summary>
/// <returns>A single contact, or <see langword="null"/> if the user cancelled the operation.</returns>
public static Task<Contact?> PickContactAsync() =>
Default.PickContactAsync();
/// <summary>
/// Gets a collection of all the contacts on the device.
/// </summary>
/// <param name="cancellationToken">A token that can be used for cancelling the operation.</param>
/// <returns>A collection of contacts on the device.</returns>
public static Task<IEnumerable<Contact>> GetAllAsync(CancellationToken cancellationToken = default) =>
Default.GetAllAsync(cancellationToken);
static IContacts? defaultImplementation;
/// <summary>
/// Provides the default implementation for static usage of this API.
/// </summary>
public static IContacts Default =>
defaultImplementation ??= new ContactsImplementation();
internal static void SetDefault(IContacts? implementation) =>
defaultImplementation = implementation;
}
}