diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 81f3412..335e54f 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -18,7 +18,7 @@ $(_IsPublishing) Some OK core utility functions https://github.com/scottbilas/OkTools - 1.0.6 + 1.0.7 README.md LICENSE.md diff --git a/src/Core/EnumerableExtensions.cs b/src/Core/EnumerableExtensions.cs index 289951e..9736c04 100644 --- a/src/Core/EnumerableExtensions.cs +++ b/src/Core/EnumerableExtensions.cs @@ -16,6 +16,11 @@ public static IEnumerable OrEmpty(this IEnumerable? @this) => public static IReadOnlyList OrEmpty(this IReadOnlyList? @this) => @this ?? Array.Empty(); + public static bool Any(this ICollection @this) => + @this.Count != 0; + public static bool IsEmpty(this ICollection @this) => + @this.Count == 0; + // singles public static T SingleOr(this IEnumerable @this, T defaultValue) diff --git a/src/Core/Sys.cs b/src/Core/Sys.cs new file mode 100644 index 0000000..3f34296 --- /dev/null +++ b/src/Core/Sys.cs @@ -0,0 +1,25 @@ +using System.Runtime.InteropServices; + +namespace OkTools.Core; + +// only care about these right now +public enum SysPlatform : byte { Windows, Mac, Linux, } +public enum SysArchitecture : byte { X64, Arm64 } + +public static class Sys +{ + public static readonly SysPlatform Platform + = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? SysPlatform.Windows + : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? SysPlatform.Mac + : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? SysPlatform.Linux + : throw new NotSupportedException("Unsupported/invalid platform"); + + // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault + public static readonly SysArchitecture Architecture + = RuntimeInformation.OSArchitecture switch + { + System.Runtime.InteropServices.Architecture.X64 => SysArchitecture.X64, + System.Runtime.InteropServices.Architecture.Arm64 => SysArchitecture.Arm64, + _ => throw new NotSupportedException("Unsupported/invalid architecture") + }; +}