-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
DeviceInfo.shared.cs
125 lines (103 loc) · 3.2 KB
/
DeviceInfo.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
#nullable enable
using System;
namespace Microsoft.Maui.Devices
{
/// <summary>
///Types of devices.
/// </summary>
public enum DeviceType
{
/// <summary>An unknown device type.</summary>
Unknown = 0,
/// <summary>The device is a physical device, such as an iPhone, Android tablet, or Windows/macOS desktop.</summary>
Physical = 1,
/// <summary>The device is virtual, such as the iOS Simulator, Android emulators, or Windows emulators.</summary>
Virtual = 2
}
/// <summary>
/// Represents information about the device.
/// </summary>
public interface IDeviceInfo
{
/// <summary>
/// Gets the model of the device.
/// </summary>
string Model { get; }
/// <summary>
/// Gets the manufacturer of the device.
/// </summary>
string Manufacturer { get; }
/// <summary>
/// Gets the name of the device.
/// </summary>
/// <remarks>This value is often specified by the user of the device.</remarks>
string Name { get; }
/// <summary>
/// Gets the string representation of the version of the operating system.
/// </summary>
string VersionString { get; }
/// <summary>
/// Gets the version of the operating system.
/// </summary>
Version Version { get; }
/// <summary>
/// Gets the platform or operating system of the device.
/// </summary>
DevicePlatform Platform { get; }
/// <summary>
/// Gets the idiom (form factor) of the device.
/// </summary>
DeviceIdiom Idiom { get; }
/// <summary>
/// Gets the type of device the application is running on.
/// </summary>
DeviceType DeviceType { get; }
}
/// <summary>
/// Represents information about the device.
/// </summary>
public static class DeviceInfo
{
/// <summary>
/// Gets the model of the device.
/// </summary>
public static string Model => Current.Model;
/// <summary>
/// Gets the manufacturer of the device.
/// </summary>
public static string Manufacturer => Current.Manufacturer;
/// <summary>
/// Gets the name of the device.
/// </summary>
/// <remarks>This value is often specified by the user of the device.</remarks>
public static string Name => Current.Name;
/// <summary>
/// Gets the string representation of the version of the operating system.
/// </summary>
public static string VersionString => Current.VersionString;
/// <summary>
/// Gets the version of the operating system.
/// </summary>
public static Version Version => Current.Version;
/// <summary>
/// Gets the platform or operating system of the device.
/// </summary>
public static DevicePlatform Platform => Current.Platform;
/// <summary>
/// Gets the idiom (form factor) of the device.
/// </summary>
public static DeviceIdiom Idiom => Current.Idiom;
/// <summary>
/// Gets the type of device the application is running on.
/// </summary>
public static DeviceType DeviceType => Current.DeviceType;
static IDeviceInfo? currentImplementation;
/// <summary>
/// Provides the default implementation for static usage of this API.
/// </summary>
public static IDeviceInfo Current =>
currentImplementation ??= new DeviceInfoImplementation();
internal static void SetCurrent(IDeviceInfo? implementation) =>
currentImplementation = implementation;
}
}