Add new official .NET guards for OS dependant code.

This commit is contained in:
2022-03-26 17:12:08 +00:00
parent 1c99cb1d09
commit a9e228a91b
3 changed files with 11 additions and 8 deletions

View File

@@ -36,7 +36,6 @@ using System;
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Interop;
using Aaru.Console;
using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
/// <summary>Contains device information</summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
@@ -102,13 +101,15 @@ public sealed partial class Device
serverArchitecture = null;
if(aaruRemote is null)
switch(DetectOS.GetRealPlatformID())
{
case PlatformID.Win32NT: return Windows.ListDevices.GetList();
case PlatformID.Linux: return Linux.ListDevices.GetList();
default:
throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported.");
}
{
if(OperatingSystem.IsWindows())
return Windows.ListDevices.GetList();
if(OperatingSystem.IsLinux())
return Linux.ListDevices.GetList();
throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported.");
}
try
{

View File

@@ -36,6 +36,7 @@ using System;
using System.IO;
using System.Text;
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
static class ListDevices
{
const string PATH_SYS_DEVBLOCK = "/sys/block/";

View File

@@ -42,6 +42,7 @@ using Aaru.Helpers;
using Microsoft.Win32.SafeHandles;
using Marshal = System.Runtime.InteropServices.Marshal;
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
static class ListDevices
{
/// <summary>Converts a hex dump string to the ASCII string it represents</summary>