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">
<PropertyGroup>
<TargetFrameworks>net452;netstandard1.5</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
@ -9,13 +9,4 @@
<PackageId>CurlSharp</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</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>

View File

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