From 3b87066317d82837097d71500d6ce166975e7895 Mon Sep 17 00:00:00 2001 From: konstantin Date: Sun, 18 Aug 2024 19:07:45 +0200 Subject: [PATCH 1/3] BO Avis: Make all Properties nullable (#499) * AvisNummer * AvisTyp * Positionen * ZuZahlen --- BO4E/BO/Avis.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/BO4E/BO/Avis.cs b/BO4E/BO/Avis.cs index 41d33e58..da866e8e 100644 --- a/BO4E/BO/Avis.cs +++ b/BO4E/BO/Avis.cs @@ -1,3 +1,4 @@ +#nullable enable using BO4E.COM; using BO4E.ENUM; using BO4E.meta; @@ -20,37 +21,37 @@ public class Avis : BusinessObject /// /// Eine im Verwendungskontext eindeutige Nummer für das Avis. /// - [JsonProperty(PropertyName = "avisNummer", Required = Required.Always)] + [JsonProperty(PropertyName = "avisNummer", Required = Required.Default)] [JsonPropertyName("avisNummer")] [NonOfficial(NonOfficialCategory.MISSING)] [ProtoMember(1000)] - public string AvisNummer { get; set; } + public string? AvisNummer { get; set; } /// /// Gibt den Typ des Avis an. /// /// - [JsonProperty(PropertyName = "avisTyp", Required = Required.Always)] + [JsonProperty(PropertyName = "avisTyp", Required = Required.Default)] [JsonPropertyName("avisTyp")] [ProtoMember(1001)] - public AvisTyp AvisTyp { get; set; } + public AvisTyp? AvisTyp { get; set; } /// /// Avispositionen /// - [JsonProperty(PropertyName = "positionen", Required = Required.Always)] + [JsonProperty(PropertyName = "positionen", Required = Required.Default)] [JsonPropertyName("positionen")] [NonOfficial(NonOfficialCategory.MISSING)] [ProtoMember(1002)] [BoKey] - public List Positionen { get; set; } + public List? Positionen { get; set; } /// /// Summenbetrag /// - [JsonProperty(PropertyName = "zuZahlen", Required = Required.Always)] + [JsonProperty(PropertyName = "zuZahlen", Required = Required.Default)] [JsonPropertyName("zuZahlen")] [NonOfficial(NonOfficialCategory.MISSING)] [ProtoMember(1003)] - public Betrag ZuZahlen { get; set; } -} \ No newline at end of file + public Betrag? ZuZahlen { get; set; } +} From 4b65363a14201b2c03e1b7f3abc1b5c410f76ad4 Mon Sep 17 00:00:00 2001 From: konstantin Date: Sun, 18 Aug 2024 19:26:32 +0200 Subject: [PATCH 2/3] chore: remove unused imports (#482) --- BO4E/BO/Lokationszuordnung.cs | 2 -- BO4E/BO/TechnischeRessource.cs | 3 +-- BO4E/COM/Bankverbindung.cs | 1 - BO4E/COM/MarktpartnerDetails.cs | 1 - BO4ETestProject/TestZeitraumDeserialization.cs | 2 -- TestBO4E.Extensions/TestEnergiemengeExtensionCompleteness.cs | 4 ---- 6 files changed, 1 insertion(+), 12 deletions(-) diff --git a/BO4E/BO/Lokationszuordnung.cs b/BO4E/BO/Lokationszuordnung.cs index af0e202e..17d48460 100644 --- a/BO4E/BO/Lokationszuordnung.cs +++ b/BO4E/BO/Lokationszuordnung.cs @@ -1,8 +1,6 @@ -using System; using System.Collections.Generic; using System.Text.Json.Serialization; using BO4E.COM; -using BO4E.ENUM; using BO4E.meta; using Newtonsoft.Json; using ProtoBuf; diff --git a/BO4E/BO/TechnischeRessource.cs b/BO4E/BO/TechnischeRessource.cs index cd1e62a1..1625d6a0 100644 --- a/BO4E/BO/TechnischeRessource.cs +++ b/BO4E/BO/TechnischeRessource.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel; using System.Text.Json.Serialization; using BO4E.COM; @@ -239,4 +238,4 @@ public class TechnischeRessource : BusinessObject [JsonPropertyOrder(24)] [NonOfficial(NonOfficialCategory.CUSTOMER_REQUIREMENTS)] public string? LokationsbuendelObjektcode { get; set; } -} \ No newline at end of file +} diff --git a/BO4E/COM/Bankverbindung.cs b/BO4E/COM/Bankverbindung.cs index 35aa17be..74bd89f1 100644 --- a/BO4E/COM/Bankverbindung.cs +++ b/BO4E/COM/Bankverbindung.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using BO4E.ENUM; using BO4E.meta; using Newtonsoft.Json; using ProtoBuf; diff --git a/BO4E/COM/MarktpartnerDetails.cs b/BO4E/COM/MarktpartnerDetails.cs index 116fc77b..714e99a1 100644 --- a/BO4E/COM/MarktpartnerDetails.cs +++ b/BO4E/COM/MarktpartnerDetails.cs @@ -1,4 +1,3 @@ -using BO4E.BO; using BO4E.meta; using Newtonsoft.Json; diff --git a/BO4ETestProject/TestZeitraumDeserialization.cs b/BO4ETestProject/TestZeitraumDeserialization.cs index 47a7b9f4..0f2bba5c 100644 --- a/BO4ETestProject/TestZeitraumDeserialization.cs +++ b/BO4ETestProject/TestZeitraumDeserialization.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using BO4E.BO; using BO4E.COM; -using BO4E.ENUM; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; diff --git a/TestBO4E.Extensions/TestEnergiemengeExtensionCompleteness.cs b/TestBO4E.Extensions/TestEnergiemengeExtensionCompleteness.cs index e94e274a..68a764ef 100644 --- a/TestBO4E.Extensions/TestEnergiemengeExtensionCompleteness.cs +++ b/TestBO4E.Extensions/TestEnergiemengeExtensionCompleteness.cs @@ -1,4 +1,3 @@ -using BO4E; using BO4E.BO; using BO4E.COM; using BO4E.ENUM; @@ -11,9 +10,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - - using System; using System.Collections.Generic; using System.IO; From 8bf4222396eba0da3521967dd2027a87e56b1a6a Mon Sep 17 00:00:00 2001 From: konstantin Date: Sun, 18 Aug 2024 19:36:19 +0200 Subject: [PATCH 3/3] Improve Nullability in `BO4E.meta` (#473) Improve Nullability --- BO4E/BoMapper.cs | 14 -------------- .../meta/BusinessObjectSerializationBinder.cs | 4 ++-- BO4E/meta/CentralEuropeStandardTime.cs | 19 +++++++++++-------- BO4E/meta/MultiLangResolver.cs | 4 ++-- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/BO4E/BoMapper.cs b/BO4E/BoMapper.cs index 3cd264f1..a98da640 100644 --- a/BO4E/BoMapper.cs +++ b/BO4E/BoMapper.cs @@ -67,18 +67,4 @@ where string.Equals(boName, businessObjectName, StringComparison.CurrentCultureI //throw new ArgumentException($"No implemented BusinessObject type matches the name '{businessObjectName}'."); } - - /// - /// Get JSON Scheme for given Business Object type - /// - /// Business Object type (e.g. typeof(BO4E.BO.Messlokation) - /// A JSON scheme to be used for validation purposes. - /// if given type is not derived from BusinessObject - public static JSchema GetJsonSchemeFor(Type businessObjectType) - { - if (!businessObjectType.IsSubclassOf(typeof(BusinessObject))) - throw new ArgumentException($"The given type {businessObjectType} is not derived from BusinessObject."); - var bo = Activator.CreateInstance(businessObjectType) as BusinessObject; - return bo.GetJsonScheme(); - } } diff --git a/BO4E/meta/BusinessObjectSerializationBinder.cs b/BO4E/meta/BusinessObjectSerializationBinder.cs index 59268034..22a81a61 100644 --- a/BO4E/meta/BusinessObjectSerializationBinder.cs +++ b/BO4E/meta/BusinessObjectSerializationBinder.cs @@ -27,13 +27,13 @@ static BusinessObjectSerializationBinder() public static IList BusinessObjectAndCOMTypes { get; } /// - public Type BindToType(string assemblyName, string typeName) + public Type BindToType(string? assemblyName, string typeName) { return BusinessObjectAndCOMTypes.SingleOrDefault(t => t.Name == typeName); } /// - public void BindToName(Type serializedType, out string assemblyName, out string typeName) + public void BindToName(Type serializedType, out string? assemblyName, out string typeName) { assemblyName = null; typeName = serializedType.Name; diff --git a/BO4E/meta/CentralEuropeStandardTime.cs b/BO4E/meta/CentralEuropeStandardTime.cs index b98a01f0..d7273e65 100644 --- a/BO4E/meta/CentralEuropeStandardTime.cs +++ b/BO4E/meta/CentralEuropeStandardTime.cs @@ -10,10 +10,15 @@ namespace BO4E.meta /// public abstract class CentralEuropeStandardTime { + private static readonly TimeZoneInfo? _CentralEuropeStandardTimezoneInfo; + /// /// Central Europe Standard Time as hard coded default time. Public to be used elsewhere ;) /// - public static readonly TimeZoneInfo CentralEuropeStandardTimezoneInfo; + public static TimeZoneInfo CentralEuropeStandardTimezoneInfo + { + get => _CentralEuropeStandardTimezoneInfo!; + } static CentralEuropeStandardTime() { @@ -24,12 +29,10 @@ static CentralEuropeStandardTime() if (stream == null) // this should never ever happen throw new FileNotFoundException($"The file resource {resourceFileName} was not found."); - using (var jsonReader = new StreamReader(stream)) - { - var jsonString = jsonReader.ReadToEnd(); - //Console.WriteLine(jsonString); - CentralEuropeStandardTimezoneInfo = JsonConvert.DeserializeObject(jsonString); - } + using var jsonReader = new StreamReader(stream); + var jsonString = jsonReader.ReadToEnd(); + //Console.WriteLine(jsonString); + _CentralEuropeStandardTimezoneInfo = JsonConvert.DeserializeObject(jsonString); } /// @@ -39,4 +42,4 @@ static CentralEuropeStandardTime() // ReSharper disable once InconsistentNaming public static TimeZoneInfo CENTRAL_EUROPE_STANDARD_TIME => CentralEuropeStandardTimezoneInfo; } -} \ No newline at end of file +} diff --git a/BO4E/meta/MultiLangResolver.cs b/BO4E/meta/MultiLangResolver.cs index 9b811eda..a2009573 100644 --- a/BO4E/meta/MultiLangResolver.cs +++ b/BO4E/meta/MultiLangResolver.cs @@ -39,7 +39,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ // See if there is a [FieldName] attribute applied to the property // for the requested language - var att = prop.AttributeProvider.GetAttributes(true) + var att = prop.AttributeProvider?.GetAttributes(true) .OfType() .FirstOrDefault(a => a.Language == _language); @@ -48,4 +48,4 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ return prop; } } -} \ No newline at end of file +}