fix: Fix nullability warnings in Class.FromBytes

This commit is contained in:
Michael Croes
2023-07-26 23:52:28 +02:00
parent 3d0dd693ba
commit c3f86c32a2

View File

@@ -227,9 +227,11 @@ namespace S7.Net.Types
{
if (property.PropertyType.IsArray)
{
Array array = (Array)property.GetValue(sourceClass, null);
Array array = (Array?) property.GetValue(sourceClass, null) ??
throw new ArgumentException($"Property {property.Name} on sourceClass must be an array instance.", nameof(sourceClass));
IncrementToEven(ref numBytes);
Type elementType = property.PropertyType.GetElementType();
Type elementType = property.PropertyType.GetElementType()!;
for (int i = 0; i < array.Length && numBytes < bytes.Length; i++)
{
array.SetValue(