Add NetStandard 1.3 support

Supersedes UWP support since UWP 10.0 supports up to NetStandard 1.4.
This commit is contained in:
Michael Croes
2018-06-30 21:40:22 +02:00
parent e516675a70
commit 7821b6b6f6
5 changed files with 60 additions and 13 deletions

View File

@@ -0,0 +1,19 @@
using System.Net.Sockets;
namespace S7.Net
{
public static class TcpClientMixins
{
#if NETSTANDARD1_3
public static void Close(this TcpClient tcpClient)
{
tcpClient.Dispose();
}
public static void Connect(this TcpClient tcpClient, string host, int port)
{
tcpClient.ConnectAsync(host, port).GetAwaiter().GetResult();
}
#endif
}
}

View File

@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
#if NET_FULL
using System.Runtime.Serialization;
#endif
namespace S7.Net
{
@@ -21,9 +20,11 @@ namespace S7.Net
{
}
#if NET_FULL
protected WrongNumberOfBytesException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
internal class InvalidAddressException : Exception
@@ -40,9 +41,11 @@ namespace S7.Net
{
}
#if NET_FULL
protected InvalidAddressException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
internal class InvalidVariableTypeException : Exception
@@ -59,9 +62,11 @@ namespace S7.Net
{
}
#if NET_FULL
protected InvalidVariableTypeException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
internal class TPKTInvalidException : Exception
@@ -78,8 +83,10 @@ namespace S7.Net
{
}
#if NET_FULL
protected TPKTInvalidException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net452;netstandard2.0;netstandard1.3</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Properties\S7.Net.snk</AssemblyOriginatorKeyFile>
<InternalsVisibleTo>S7.Net.UnitTest</InternalsVisibleTo>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>NET_FULL</DefineConstants>
</PropertyGroup>
</Project>

View File

@@ -13,8 +13,8 @@ namespace S7.Net.Types
private static IEnumerable<PropertyInfo> GetAccessableProperties(Type classType)
{
return classType
#if NETFX_CORE
.GetProperties().Where(p => p.GetSetMethod() != null);
#if NETSTANDARD1_3
.GetTypeInfo().DeclaredProperties.Where(p => p.SetMethod != null);
#else
.GetProperties(
BindingFlags.SetProperty |

View File

@@ -19,7 +19,13 @@ namespace S7.Net.Types
{
double numBytes = 0.0;
System.Reflection.FieldInfo[] infos = structType.GetFields();
var infos = structType
#if NETSTANDARD1_3
.GetTypeInfo().DeclaredFields;
#else
.GetFields();
#endif
foreach (System.Reflection.FieldInfo info in infos)
{
switch (info.FieldType.Name)
@@ -80,7 +86,14 @@ namespace S7.Net.Types
double numBytes = 0.0;
object structValue = Activator.CreateInstance(structType);
System.Reflection.FieldInfo[] infos = structValue.GetType().GetFields();
var infos = structValue.GetType()
#if NETSTANDARD1_3
.GetTypeInfo().DeclaredFields;
#else
.GetFields();
#endif
foreach (System.Reflection.FieldInfo info in infos)
{
switch (info.FieldType.Name)
@@ -182,7 +195,13 @@ namespace S7.Net.Types
int bitPos = 0;
double numBytes = 0.0;
System.Reflection.FieldInfo[] infos = type.GetFields();
var infos = type
#if NETSTANDARD1_3
.GetTypeInfo().DeclaredFields;
#else
.GetFields();
#endif
foreach (System.Reflection.FieldInfo info in infos)
{
bytes2 = null;