Use platform detection that works on mono 4.6+ (#2055)

This commit is contained in:
Nathan Holland 2017-11-01 23:37:51 +13:00 committed by flightlevel
parent 5c35ada012
commit 36bd2c032f
2 changed files with 13 additions and 22 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net452;netstandard1.5</TargetFrameworks> <TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
@ -9,13 +9,4 @@
<PackageId>CurlSharp</PackageId> <PackageId>CurlSharp</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.5'">
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
</ItemGroup>
</Project> </Project>

View File

@ -46,16 +46,16 @@ namespace CurlSharp
static NativeMethods() static NativeMethods()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{ {
switch (RuntimeInformation.OSArchitecture) if (Environment.Is64BitOperatingSystem)
{ {
case Architecture.X64: SetDllDirectory(Path.Combine(AssemblyDirectory, LIB_DIR_WIN64));
SetDllDirectory(Path.Combine(AssemblyDirectory, LIB_DIR_WIN64)); }
break; else
case Architecture.X86: {
SetDllDirectory(Path.Combine(AssemblyDirectory, LIB_DIR_WIN32)); SetDllDirectory(Path.Combine(AssemblyDirectory, LIB_DIR_WIN32));
break;
} }
} }
#if USE_LIBCURLSHIM #if USE_LIBCURLSHIM
@ -63,11 +63,11 @@ namespace CurlSharp
throw new InvalidOperationException("Can not run on other platform than Win NET"); throw new InvalidOperationException("Can not run on other platform than Win NET");
#endif #endif
} }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetDllDirectory(string lpPathName); private static extern bool SetDllDirectory(string lpPathName);
private static string AssemblyDirectory private static string AssemblyDirectory
{ {
get get
@ -334,7 +334,7 @@ namespace CurlSharp
{ {
var handle = Create(); var handle = Create();
handle.fd_count = 1; handle.fd_count = 1;
handle.fd_array[0] = (uint) socket; handle.fd_array[0] = (uint)socket;
return handle; return handle;
} }
} }
@ -400,7 +400,7 @@ namespace CurlSharp
{ {
int result; int result;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{ {
result = select_win( result = select_win(
nfds, // number of sockets, (ignored in winsock) nfds, // number of sockets, (ignored in winsock)