mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 14:28:25 +08:00
Types.Class.ToBytes doesn't need a type information, because the object is passed as parameter anyway
This commit is contained in:
@@ -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.");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user