From 87aea601ac38bd0463d2b8fc082a9e238a3cd051 Mon Sep 17 00:00:00 2001 From: konstantin Date: Sun, 18 Aug 2024 17:33:56 +0200 Subject: [PATCH] Make nullability asssumptions explicit in `VertragsConverter` --- BO4E/BO/Vertrag.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BO4E/BO/Vertrag.cs b/BO4E/BO/Vertrag.cs index fb56cb5d..49e9db8b 100644 --- a/BO4E/BO/Vertrag.cs +++ b/BO4E/BO/Vertrag.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Text.Json; @@ -251,15 +252,19 @@ public override Vertrag Read(ref Utf8JsonReader reader, Type typeToConvert, Json } var v = JsonSerializer.Deserialize(ref reader, Vertrag.VertragsSerializerOptions); + if (v is null) + { + throw new InvalidDataException("Could not deserialize Vertrag"); + } if ((v.Vertragsteile == null || v.Vertragsteile.Count == 0) && v.UserProperties != null && - v.UserProperties.ContainsKey("lokationsId")) + v.UserProperties.TryGetValue("lokationsId", out var property)) v.Vertragsteile = new List { new() { Vertragsteilbeginn = v.Vertragsbeginn, Vertragsteilende = v.Vertragsende, - Lokation = ((JsonElement) v.UserProperties["lokationsId"]).GetString() + Lokation = ((JsonElement) property).GetString() } }; return v;