Skip to content

Commit

Permalink
Moved some code over
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbilas committed Nov 24, 2023
1 parent d2b8fc2 commit 830d248
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<GeneratePackageOnBuild>$(_IsPublishing)</GeneratePackageOnBuild>
<Title>Some OK core utility functions</Title>
<RepositoryUrl>https://github.com/scottbilas/OkTools</RepositoryUrl>
<PackageVersion>1.0.6</PackageVersion>
<PackageVersion>1.0.7</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Core/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public static IEnumerable<T> OrEmpty<T>(this IEnumerable<T>? @this) =>
public static IReadOnlyList<T> OrEmpty<T>(this IReadOnlyList<T>? @this) =>
@this ?? Array.Empty<T>();

public static bool Any<T>(this ICollection<T> @this) =>
@this.Count != 0;
public static bool IsEmpty<T>(this ICollection<T> @this) =>
@this.Count == 0;

// singles

public static T SingleOr<T>(this IEnumerable<T> @this, T defaultValue)
Expand Down
25 changes: 25 additions & 0 deletions src/Core/Sys.cs
Original file line number Diff line number Diff line change
@@ -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")
};
}

0 comments on commit 830d248

Please sign in to comment.