From 099e32ce8ab5719128169635c0540ccc571a8cf9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 12 Jun 2026 06:45:56 +0000 Subject: [PATCH] Fix IDE0370 build errors from .NET 10 SDK analyzer The scheduled CI build failed with 32 IDE0370 (suppression is unnecessary) errors raised by the .NET SDK 10.0.301 analyzers with warnings treated as errors. - SemanticQuantity.cs: remove null-forgiving operators on Create(...) calls; Create returns a non-nullable TQuantity so the suppressions were never needed. - SemanticString.cs: replace null-forgiving operators in FromStringInternal with Ensure.NotNull, which is valid in both the nullable-annotated (net5.0+) and oblivious (netstandard2.x) builds where IDE0370 flagged the suppressions. https://claude.ai/code/session_01LBGrmJHgP4RpMC9dQ2Pdox --- Semantics.Quantities/Core/SemanticQuantity.cs | 14 +++++++------- Semantics.Strings/SemanticString.cs | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Semantics.Quantities/Core/SemanticQuantity.cs b/Semantics.Quantities/Core/SemanticQuantity.cs index 26b9f6e..72649d7 100644 --- a/Semantics.Quantities/Core/SemanticQuantity.cs +++ b/Semantics.Quantities/Core/SemanticQuantity.cs @@ -67,7 +67,7 @@ public static TResult Multiply(SemanticQuantity self, Semanti { Ensure.NotNull(self); Ensure.NotNull(other); - return Create(self.Quantity * other.Quantity)!; + return Create(self.Quantity * other.Quantity); } /// @@ -81,7 +81,7 @@ public static TResult Multiply(SemanticQuantity self, TStorag where TResult : SemanticQuantity, new() { Ensure.NotNull(self); - return Create(self.Quantity * other)!; + return Create(self.Quantity * other); } /// @@ -96,7 +96,7 @@ public static TResult Divide(SemanticQuantity self, SemanticQ { Ensure.NotNull(self); Ensure.NotNull(other); - return Create(self.Quantity / other.Quantity)!; + return Create(self.Quantity / other.Quantity); } /// @@ -110,7 +110,7 @@ public static TResult Divide(SemanticQuantity self, TStorage where TResult : SemanticQuantity, new() { Ensure.NotNull(self); - return Create(self.Quantity / other)!; + return Create(self.Quantity / other); } /// @@ -142,7 +142,7 @@ public static TResult Add(SemanticQuantity self, SemanticQuan { Ensure.NotNull(self); Ensure.NotNull(other); - return Create(self.Quantity + other.Quantity)!; + return Create(self.Quantity + other.Quantity); } /// @@ -157,7 +157,7 @@ public static TResult Subtract(SemanticQuantity self, Semanti { Ensure.NotNull(self); Ensure.NotNull(other); - return Create(self.Quantity - other.Quantity)!; + return Create(self.Quantity - other.Quantity); } /// @@ -170,7 +170,7 @@ public static TResult Negate(SemanticQuantity self) where TResult : SemanticQuantity, new() { Ensure.NotNull(self); - return Create(-self.Quantity)!; + return Create(-self.Quantity); } /// diff --git a/Semantics.Strings/SemanticString.cs b/Semantics.Strings/SemanticString.cs index 7fdc529..1063772 100644 --- a/Semantics.Strings/SemanticString.cs +++ b/Semantics.Strings/SemanticString.cs @@ -9,6 +9,7 @@ namespace ktsu.Semantics.Strings; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Reflection; using System.Text; using System.Text.Json.Serialization; @@ -557,8 +558,9 @@ private static TDest FromStringInternal(string? value) Ensure.NotNull(value); Type typeOfTDest = typeof(TDest); - TDest newInstance = (TDest)Activator.CreateInstance(type: typeOfTDest)!; - typeOfTDest.GetProperty(name: nameof(WeakString))!.SetValue(obj: newInstance, value: newInstance.MakeCanonical(value)); + TDest newInstance = (TDest)Ensure.NotNull(Activator.CreateInstance(type: typeOfTDest)); + PropertyInfo weakStringProperty = Ensure.NotNull(typeOfTDest.GetProperty(name: nameof(WeakString))); + weakStringProperty.SetValue(obj: newInstance, value: newInstance.MakeCanonical(value)); return newInstance; }