1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
+ using System . Diagnostics . CodeAnalysis ;
4
5
using System . IO ;
5
6
using System . Linq ;
6
7
using System . Runtime . InteropServices ;
8
+ using System . Runtime . Versioning ;
7
9
using GitCredentialManager . Interop . Posix . Native ;
8
10
9
11
namespace GitCredentialManager
@@ -24,6 +26,7 @@ public static PlatformInformation GetPlatformInformation(ITrace2 trace2)
24
26
return new PlatformInformation ( osType , osVersion , cpuArch , clrVersion ) ;
25
27
}
26
28
29
+ [ SupportedOSPlatformGuard ( Constants . WindowsPlatformName ) ]
27
30
public static bool IsDevBox ( )
28
31
{
29
32
if ( ! IsWindows ( ) )
@@ -49,6 +52,7 @@ public static bool IsDevBox()
49
52
}
50
53
}
51
54
55
+ [ SupportedOSPlatformGuard ( Constants . WindowsPlatformName ) ]
52
56
public static bool IsWindowsBrokerSupported ( )
53
57
{
54
58
if ( ! IsWindows ( ) )
@@ -93,33 +97,38 @@ public static bool IsWindowsBrokerSupported()
93
97
/// Check if the current Operating System is macOS.
94
98
/// </summary>
95
99
/// <returns>True if running on macOS, false otherwise.</returns>
100
+ [ SupportedOSPlatformGuard ( Constants . MacOSPlatformName ) ]
96
101
public static bool IsMacOS ( )
97
102
{
98
- return RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ;
103
+ return OperatingSystem . IsMacOS ( ) ;
99
104
}
100
105
101
106
/// <summary>
102
107
/// Check if the current Operating System is Windows.
103
108
/// </summary>
104
109
/// <returns>True if running on Windows, false otherwise.</returns>
110
+ [ SupportedOSPlatformGuard ( Constants . WindowsPlatformName ) ]
105
111
public static bool IsWindows ( )
106
112
{
107
- return RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
113
+ return OperatingSystem . IsWindows ( ) ;
108
114
}
109
115
110
116
/// <summary>
111
117
/// Check if the current Operating System is Linux-based.
112
118
/// </summary>
113
119
/// <returns>True if running on a Linux distribution, false otherwise.</returns>
120
+ [ SupportedOSPlatformGuard ( Constants . LinuxPlatformName ) ]
114
121
public static bool IsLinux ( )
115
122
{
116
- return RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ;
123
+ return OperatingSystem . IsLinux ( ) ;
117
124
}
118
125
119
126
/// <summary>
120
127
/// Check if the current Operating System is POSIX-compliant.
121
128
/// </summary>
122
129
/// <returns>True if running on a POSIX-compliant Operating System, false otherwise.</returns>
130
+ [ SupportedOSPlatformGuard ( Constants . LinuxPlatformName ) ]
131
+ [ SupportedOSPlatformGuard ( Constants . MacOSPlatformName ) ]
123
132
public static bool IsPosix ( )
124
133
{
125
134
return IsMacOS ( ) || IsLinux ( ) ;
@@ -129,6 +138,7 @@ public static bool IsPosix()
129
138
/// Ensure the current Operating System is macOS, fail otherwise.
130
139
/// </summary>
131
140
/// <exception cref="PlatformNotSupportedException">Thrown if the current OS is not macOS.</exception>
141
+ [ SupportedOSPlatformGuard ( Constants . MacOSPlatformName ) ]
132
142
public static void EnsureMacOS ( )
133
143
{
134
144
if ( ! IsMacOS ( ) )
@@ -141,6 +151,7 @@ public static void EnsureMacOS()
141
151
/// Ensure the current Operating System is Windows, fail otherwise.
142
152
/// </summary>
143
153
/// <exception cref="PlatformNotSupportedException">Thrown if the current OS is not Windows.</exception>
154
+ [ SupportedOSPlatformGuard ( Constants . WindowsPlatformName ) ]
144
155
public static void EnsureWindows ( )
145
156
{
146
157
if ( ! IsWindows ( ) )
@@ -153,6 +164,7 @@ public static void EnsureWindows()
153
164
/// Ensure the current Operating System is Linux-based, fail otherwise.
154
165
/// </summary>
155
166
/// <exception cref="PlatformNotSupportedException">Thrown if the current OS is not Linux-based.</exception>
167
+ [ SupportedOSPlatformGuard ( Constants . LinuxPlatformName ) ]
156
168
public static void EnsureLinux ( )
157
169
{
158
170
if ( ! IsLinux ( ) )
@@ -165,6 +177,8 @@ public static void EnsureLinux()
165
177
/// Ensure the current Operating System is POSIX-compliant, fail otherwise.
166
178
/// </summary>
167
179
/// <exception cref="PlatformNotSupportedException">Thrown if the current OS is not POSIX-compliant.</exception>
180
+ [ SupportedOSPlatformGuard ( Constants . LinuxPlatformName ) ]
181
+ [ SupportedOSPlatformGuard ( Constants . MacOSPlatformName ) ]
168
182
public static void EnsurePosix ( )
169
183
{
170
184
if ( ! IsPosix ( ) )
0 commit comments