Skip to content

Commit 0c1fc3d

Browse files
committed
Add SupportedOSPlatformGuardAttribute
1 parent 4ee1d3d commit 0c1fc3d

12 files changed

+101
-5
lines changed

OperatingSystem2.android.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#if __HAVE_XAMARIN_ESSENTIALS__
66
using Xamarin.Essentials;
77
#endif
8+
using System.Runtime.Versioning;
89

910
namespace System
1011
{
@@ -13,6 +14,7 @@ partial class OperatingSystem2
1314
/// <summary>
1415
/// 指示当前应用程序是否正在 Android 上运行。
1516
/// </summary>
17+
[SupportedOSPlatformGuard("android")]
1618
public static bool IsAndroid =>
1719
#if __ANDROID__
1820
true;
@@ -44,6 +46,7 @@ partial class OperatingSystem2
4446
/// <summary>
4547
/// 指示当前应用程序是否正在 Windows Subsystem for Android™️ 上运行。
4648
/// </summary>
49+
[SupportedOSPlatformGuard("android")]
4750
public static bool IsRunningOnWSA =>
4851
#if __ANDROID__
4952
_IsRunningOnWSA.Value;
@@ -56,6 +59,7 @@ partial class OperatingSystem2
5659
/// </summary>
5760
/// <param name="sdkInt"></param>
5861
/// <returns></returns>
62+
[SupportedOSPlatformGuard("android")]
5963
public static bool IsAndroidVersionAtLeast(int sdkInt)
6064
{
6165
#if __ANDROID__
@@ -71,6 +75,7 @@ public static bool IsAndroidVersionAtLeast(int sdkInt)
7175
/// </summary>
7276
/// <param name="sdkInt"></param>
7377
/// <returns></returns>
78+
[SupportedOSPlatformGuard("android")]
7479
public static bool IsAndroidVersionAtLeast(BuildVersionCodes sdkInt)
7580
{
7681
return Build.VERSION.SdkInt >= sdkInt;
@@ -85,6 +90,7 @@ public static bool IsAndroidVersionAtLeast(BuildVersionCodes sdkInt)
8590
/// <param name="build"></param>
8691
/// <param name="revision"></param>
8792
/// <returns></returns>
93+
[SupportedOSPlatformGuard("android")]
8894
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
8995
{
9096
#if NET5_0 || NET6_0 || NET7_0

OperatingSystem2.application.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
53

64
namespace System
75
{

OperatingSystem2.browser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#if __HAVE_RUNTIME_INFORMATION__
1+
#if __HAVE_RUNTIME_INFORMATION__
22
using System.Runtime.InteropServices;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,7 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否在浏览器中作为 WASM 运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("browser")]
1214
public static bool IsBrowser =>
1315
#if NET5_0 || NET6_0 || NET7_0
1416
OperatingSystem.IsBrowser();

OperatingSystem2.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Description>表示有关操作系统的信息,如版本和平台标识符的通用库。</Description>
2222
<PackageId>OperatingSystem2</PackageId>
2323
<GenerateDocumentationFile>true</GenerateDocumentationFile>
24-
<Version>1.4.2.1</Version>
24+
<Version>1.4.3</Version>
2525
<AndroidUseIntermediateDesignerFile>false</AndroidUseIntermediateDesignerFile>
2626
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
2727
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -43,7 +43,7 @@
4343
</ItemGroup>
4444

4545
<ItemGroup>
46-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
46+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
4747
</ItemGroup>
4848

4949
</Project>

OperatingSystem2.freebsd.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if NETCOREAPP3_0 || NETCOREAPP3_1
22
using System.Runtime.InteropServices;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,7 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否正在 FreeBSD 上运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("freebsd")]
1214
public static bool IsFreeBSD =>
1315
#if NET5_0 || NET6_0 || NET7_0
1416
OperatingSystem.IsFreeBSD();
@@ -26,6 +28,7 @@ partial class OperatingSystem2
2628
/// <param name="build"></param>
2729
/// <param name="revision"></param>
2830
/// <returns></returns>
31+
[SupportedOSPlatformGuard("freebsd")]
2932
public static bool IsFreeBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
3033
{
3134
#if NET5_0 || NET6_0 || NET7_0

OperatingSystem2.ios.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if __HAVE_XAMARIN_ESSENTIALS__
22
using Xamarin.Essentials;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,8 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否正在 iOS 上运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("ios")]
14+
[SupportedOSPlatformGuard("maccatalyst")]
1215
public static bool IsIOS =>
1316
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __WATCHOS__
1417
false;
@@ -29,6 +32,8 @@ partial class OperatingSystem2
2932
/// <param name="minor"></param>
3033
/// <param name="build"></param>
3134
/// <returns></returns>
35+
[SupportedOSPlatformGuard("ios")]
36+
[SupportedOSPlatformGuard("maccatalyst")]
3237
public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0)
3338
{
3439
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __WATCHOS__

OperatingSystem2.linux.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if __HAVE_RUNTIME_INFORMATION__
22
using System.Runtime.InteropServices;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,7 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否正在 Linux 上运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("linux")]
1214
public static bool IsLinux =>
1315
#if NETSTANDARD1_0 || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __MACOS__ || __IOS__ || __WATCHOS__ || __TVOS__ || WINDOWS_UWP
1416
false;

OperatingSystem2.macos.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#if __HAVE_XAMARIN_ESSENTIALS__
55
using Xamarin.Essentials;
66
#endif
7+
using System.Runtime.Versioning;
78

89
namespace System
910
{
@@ -12,6 +13,7 @@ partial class OperatingSystem2
1213
/// <summary>
1314
/// 指示当前应用程序是否正在 macOS 上运行。
1415
/// </summary>
16+
[SupportedOSPlatformGuard("macos")]
1517
public static bool IsMacOS =>
1618
#if NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __WATCHOS__ || WINDOWS_UWP
1719
false;
@@ -34,6 +36,7 @@ partial class OperatingSystem2
3436
/// <param name="minor"></param>
3537
/// <param name="build"></param>
3638
/// <returns></returns>
39+
[SupportedOSPlatformGuard("macos")]
3740
public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0)
3841
{
3942
#if NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __WATCHOS__ || WINDOWS_UWP

OperatingSystem2.tvos.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if __HAVE_XAMARIN_ESSENTIALS__
22
using Xamarin.Essentials;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,7 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否正在 tvOS 上运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("tvos")]
1214
public static bool IsTvOS =>
1315
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __IOS__ || __WATCHOS__
1416
false;
@@ -29,6 +31,7 @@ partial class OperatingSystem2
2931
/// <param name="minor"></param>
3032
/// <param name="build"></param>
3133
/// <returns></returns>
34+
[SupportedOSPlatformGuard("tvos")]
3235
public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0)
3336
{
3437
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __IOS__ || __WATCHOS__

OperatingSystem2.watchos.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if __HAVE_XAMARIN_ESSENTIALS__
22
using Xamarin.Essentials;
33
#endif
4+
using System.Runtime.Versioning;
45

56
namespace System
67
{
@@ -9,6 +10,7 @@ partial class OperatingSystem2
910
/// <summary>
1011
/// 指示当前应用程序是否正在 watchOS 上运行。
1112
/// </summary>
13+
[SupportedOSPlatformGuard("watchos")]
1214
public static bool IsWatchOS =>
1315
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __IOS__
1416
false;
@@ -29,6 +31,7 @@ partial class OperatingSystem2
2931
/// <param name="minor"></param>
3032
/// <param name="build"></param>
3133
/// <returns></returns>
34+
[SupportedOSPlatformGuard("watchos")]
3235
public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0)
3336
{
3437
#if __MACOS__ || NET5_0_WINDOWS || NET6_0_WINDOWS || NET7_0_WINDOWS || __ANDROID__ || __TVOS__ || __IOS__

0 commit comments

Comments
 (0)