Types.Class.ToBytes doesn't need a type information, because the object is passed as parameter anyway

This commit is contained in:
Thomas Bargetz
2017-08-07 12:06:03 +02:00
parent 07fe703b3d
commit 6d7edc9f86
2 changed files with 5 additions and 5 deletions

View File

@@ -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.");

View File

@@ -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;