From 6d7edc9f8678a8e16e04c68918c3ef5bf4a0ef17 Mon Sep 17 00:00:00 2001 From: Thomas Bargetz Date: Mon, 7 Aug 2017 12:06:03 +0200 Subject: [PATCH] Types.Class.ToBytes doesn't need a type information, because the object is passed as parameter anyway --- S7.Net.UnitTest/S7NetTests.cs | 2 +- S7.Net/Types/Class.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/S7.Net.UnitTest/S7NetTests.cs b/S7.Net.UnitTest/S7NetTests.cs index f034377..c70a687 100644 --- a/S7.Net.UnitTest/S7NetTests.cs +++ b/S7.Net.UnitTest/S7NetTests.cs @@ -711,7 +711,7 @@ namespace S7.Net.UnitTest } [TestMethod] - public void T22_ReadClassWithArrayAndCustomType() + public void T23_ReadClassWithArrayAndCustomType() { Assert.IsTrue(plc.IsConnected, "Before executing this test, the plc must be connected. Check constructor."); diff --git a/S7.Net/Types/Class.cs b/S7.Net/Types/Class.cs index 0a97c7d..794b469 100644 --- a/S7.Net/Types/Class.cs +++ b/S7.Net/Types/Class.cs @@ -233,13 +233,13 @@ namespace S7.Net.Types } } - private static void ToBytes(Type propertyType, object propertyValue, byte[] bytes, ref double numBytes) + private static void ToBytes(object propertyValue, byte[] bytes, ref double numBytes) { int bytePos = 0; int bitPos = 0; byte[] bytes2 = null; - switch (propertyType.Name) + switch (propertyValue.GetType().Name) { case "Boolean": // get the value @@ -310,12 +310,12 @@ namespace S7.Net.Types Type elementType = property.PropertyType.GetElementType(); for (int i = 0; i < array.Length && numBytes < bytes.Length; i++) { - ToBytes(elementType, array.GetValue(i), bytes, ref numBytes); + ToBytes(array.GetValue(i), bytes, ref numBytes); } } else { - ToBytes(property.PropertyType, property.GetValue(sourceClass, null), bytes, ref numBytes); + ToBytes(property.GetValue(sourceClass, null), bytes, ref numBytes); } } return bytes;