From c3f86c32a2a2ac1d55583e42de7975149354403c Mon Sep 17 00:00:00 2001 From: Michael Croes Date: Wed, 26 Jul 2023 23:52:28 +0200 Subject: [PATCH] fix: Fix nullability warnings in Class.FromBytes --- S7.Net/Types/Class.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/S7.Net/Types/Class.cs b/S7.Net/Types/Class.cs index 0b2b34b..c333d83 100644 --- a/S7.Net/Types/Class.cs +++ b/S7.Net/Types/Class.cs @@ -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(