From 66aa5b779942df4de03c1f79cb14f0fc497fdd3e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 05:19:39 +0200 Subject: [PATCH] Make PlatformConfiguration properties trimmable (#2717) (#2734) (cherry picked from commit 8c296e556d1cd308ce63dc68f8673c2810ecb6e0) Co-authored-by: Max Katz --- .../Binding.Shared/PlatformConfiguration.cs | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/binding/Binding.Shared/PlatformConfiguration.cs b/binding/Binding.Shared/PlatformConfiguration.cs index 6e62452bf6..ec6528eda1 100644 --- a/binding/Binding.Shared/PlatformConfiguration.cs +++ b/binding/Binding.Shared/PlatformConfiguration.cs @@ -16,42 +16,52 @@ public static class PlatformConfiguration { private const string LibCLibrary = "libc"; - public static bool IsUnix { get; } + public static bool IsUnix => IsMac || IsLinux; - public static bool IsWindows { get; } - - public static bool IsMac { get; } - - public static bool IsLinux { get; } - - public static bool IsArm { get; } - - public static bool Is64Bit { get; } + public static bool IsWindows { +#if WINDOWS_UWP + get => true; +#elif NET6_0_OR_GREATER + get => OperatingSystem.IsWindows (); +#else + get => RuntimeInformation.IsOSPlatform (OSPlatform.Windows); +#endif + } - static PlatformConfiguration () - { + public static bool IsMac { #if WINDOWS_UWP - IsMac = false; - IsLinux = false; - IsUnix = false; - IsWindows = true; - - var arch = Package.Current.Id.Architecture; - const ProcessorArchitecture arm64 = (ProcessorArchitecture)12; - IsArm = arch == ProcessorArchitecture.Arm || arch == arm64; + get => false; +#elif NET6_0_OR_GREATER + get => OperatingSystem.IsMacOS (); #else - IsMac = RuntimeInformation.IsOSPlatform (OSPlatform.OSX); - IsLinux = RuntimeInformation.IsOSPlatform (OSPlatform.Linux); - IsUnix = IsMac || IsLinux; - IsWindows = RuntimeInformation.IsOSPlatform (OSPlatform.Windows); + get => RuntimeInformation.IsOSPlatform (OSPlatform.OSX); +#endif + } - var arch = RuntimeInformation.ProcessArchitecture; - IsArm = arch == Architecture.Arm || arch == Architecture.Arm64; + public static bool IsLinux { +#if WINDOWS_UWP + get => false; +#elif NET6_0_OR_GREATER + get => OperatingSystem.IsLinux (); +#else + get => RuntimeInformation.IsOSPlatform (OSPlatform.Linux); #endif + } - Is64Bit = IntPtr.Size == 8; + public static bool IsArm { +#if WINDOWS_UWP + get { + var arch = Package.Current.Id.Architecture; + const ProcessorArchitecture arm64 = (ProcessorArchitecture)12; + return arch == ProcessorArchitecture.Arm || arch == arm64; + } +#else + get => RuntimeInformation.ProcessArchitecture is Architecture.Arm or Architecture.Arm64; +#endif } + public static bool Is64Bit => IntPtr.Size == 8; + private static string linuxFlavor; public static string LinuxFlavor