From 16e7a95d60e62537c674aafbe5442d0222ff852c Mon Sep 17 00:00:00 2001 From: Blaise Taylor Date: Wed, 4 Feb 2026 09:35:39 -0500 Subject: [PATCH 1/2] AB#16 Fixing Code Quality Warnings - part 1. --- .../ComponentModel/Design/Helpers.cs | 2 -- .../WorkflowMarkupSerializationException.cs | 11 ----------- .../Serialization/WorkflowMarkupSerializer.cs | 7 ++----- .../ComponentModel/Serialization/XamlInterfaces.cs | 5 ++--- .../SR.cs | 4 ---- .../Utility.cs | 3 --- .../WorkflowMarkupSerializerMappingTest.cs | 2 ++ Workflow.ComponentModel.Serialization.Tests/SRTest.cs | 1 + .../UtilityTest.cs | 4 ++++ 9 files changed, 11 insertions(+), 28 deletions(-) diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs index ec367be..a81bb11 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs @@ -27,9 +27,7 @@ internal static XmlWriter CreateXmlWriter(object output) return XmlWriter.Create(output as TextWriter, settings); else { -#if !UNITTESTS && DEBUG Debug.Assert(false, "Invalid argument type. 'output' must either be string or TextWriter."); -#endif return null; } } diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializationException.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializationException.cs index 588d557..218c347 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializationException.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializationException.cs @@ -49,17 +49,6 @@ protected WorkflowMarkupSerializationException(SerializationInfo info, Streaming this.columnNumber = info.GetInt32("columnNumber"); } - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - throw new ArgumentNullException("info"); - - base.GetObjectData(info, context); - - info.AddValue("lineNumber", this.lineNumber, typeof(int)); - info.AddValue("columnNumber", this.columnNumber, typeof(int)); - } - public int LineNumber { get diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs index e96e0a0..d092838 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs @@ -359,7 +359,7 @@ private void DeserializeContents(WorkflowMarkupSerializationManager serializatio //DependencyProperty dependencyProperty = ResolveDependencyProperty(serializationManager, reader, obj, reader.LocalName); if (property == null) serializationManager.ReportError(CreateSerializationError(SR.GetString(SR.Error_InvalidElementFoundForType, reader.LocalName, obj.GetType().FullName), reader)); - else if (property != null) + else { //Deserialize the compound property serializationManager.Context.Push(property); @@ -1004,9 +1004,7 @@ private object InternalDeserializeFromString(WorkflowMarkupSerializationManager object propVal = null; if (!(serializationManager.WorkflowMarkupStack[typeof(XmlReader)] is XmlReader reader)) { -#if !UNITTESTS && DEBUG Debug.Assert(false, "XmlReader not available."); -#endif return null; } if (IsValidCompactAttributeFormat(value)) @@ -1358,8 +1356,7 @@ private void DeserializeCompoundProperty(WorkflowMarkupSerializationManager seri if (isReadOnly) { object propValue = null; - if (property != null) - propValue = property.CanRead ? property.GetValue(obj, null) : null; + propValue = property.CanRead ? property.GetValue(obj, null) : null; if (propValue != null) DeserializeContents(serializationManager, propValue, reader); diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs index 0d37b2b..127e7d7 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs @@ -182,13 +182,12 @@ public override object ProvideValue(IServiceProvider provider) type = manager.GetType(new XmlQualifiedName(typename, reader.LookupNamespace(string.Empty))); // To Support Beta2 format - if (type == null) + if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null) { // If not design mode, get the value from serialization manager // At design time, we need to get the type from ITypeProvider else // we need to store the string in the hashtable we maintain internally - if (type == null && manager.GetService(typeof(ITypeResolutionService)) == null) - type = manager.SerializationManager.GetType(typename); + type = manager.SerializationManager.GetType(typename); } if (type != null) return type; diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs index 3f392bd..cb0f4b7 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs @@ -109,9 +109,7 @@ internal static string GetString(CultureInfo culture, string name, params object if (sys == null) return null; string res = sys.resources.GetString(name, culture); -#if !UNITTESTS && DEBUG System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name })); -#endif if (args != null && args.Length > 0) { return string.Format(CultureInfo.CurrentCulture, res, args); @@ -133,9 +131,7 @@ internal static string GetString(CultureInfo culture, string name) if (sys == null) return null; string res = sys.resources.GetString(name, culture); -#if !UNITTESTS && DEBUG System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name })); -#endif return res; } diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/Utility.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/Utility.cs index 3ddf93b..33abcfb 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/Utility.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/Utility.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; [assembly: CLSCompliant(true)] @@ -23,9 +22,7 @@ internal static Guid CreateGuid(string guidString) { if (!success) { -#if !UNITTESTS && DEBUG System.Diagnostics.Debug.Assert(false, "Creation of the Guid failed."); -#endif } } diff --git a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs index cc3dff5..2a9ce8d 100644 --- a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs @@ -2,6 +2,7 @@ using LogicBuilder.Workflow.ComponentModel.Serialization; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; using System.Xml; @@ -373,6 +374,7 @@ public void Equals_WithDifferentUnifiedAssemblyName_ReturnsFalse() } [Fact] + [SuppressMessage("Style", "CA1062:Validate arguments of public methods", Justification = "Testing explicit null handling")] public void Equals_WithNull_ReturnsFalse() { // Arrange diff --git a/Workflow.ComponentModel.Serialization.Tests/SRTest.cs b/Workflow.ComponentModel.Serialization.Tests/SRTest.cs index 67d5ab1..9b2b53f 100644 --- a/Workflow.ComponentModel.Serialization.Tests/SRTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/SRTest.cs @@ -176,6 +176,7 @@ public void SRDescriptionAttribute_SetsDescriptionValue_WhenCreatedWithResourceK public void SRDescriptionAttribute_ReturnsEmptyString_WhenResourceKeyDoesNotExist() { // Arrange & Act + System.Diagnostics.Trace.Listeners.Clear(); var attribute = new SRDescriptionAttribute("NonExistentKey12345"); // Assert diff --git a/Workflow.ComponentModel.Serialization.Tests/UtilityTest.cs b/Workflow.ComponentModel.Serialization.Tests/UtilityTest.cs index c775b20..9cdbf73 100644 --- a/Workflow.ComponentModel.Serialization.Tests/UtilityTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/UtilityTest.cs @@ -52,6 +52,7 @@ public void CreateGuid_ReturnsValidGuid_WhenGuidStringHasBraces() public void CreateGuid_ReturnsValidGuid_WhenGuidStringHasParentheses() { // Arrange + System.Diagnostics.Trace.Listeners.Clear(); string guidString = "(12345678-1234-1234-1234-123456789abc)"; Guid expected = new(guidString); @@ -66,6 +67,7 @@ public void CreateGuid_ReturnsValidGuid_WhenGuidStringHasParentheses() public void CreateGuid_ThrowsArgumentNullException_WhenGuidStringIsNull() { // Arrange + System.Diagnostics.Trace.Listeners.Clear(); string guidString = null!; // Act & Assert @@ -76,6 +78,7 @@ public void CreateGuid_ThrowsArgumentNullException_WhenGuidStringIsNull() public void CreateGuid_ThrowsFormatException_WhenGuidStringIsInvalid() { // Arrange + System.Diagnostics.Trace.Listeners.Clear(); string guidString = "invalid-guid-string"; // Act & Assert @@ -96,6 +99,7 @@ public void CreateGuid_ThrowsFormatException_WhenGuidStringIsEmpty() public void CreateGuid_ThrowsFormatException_WhenGuidStringIsTooShort() { // Arrange + System.Diagnostics.Trace.Listeners.Clear(); string guidString = "12345678"; // Act & Assert From f360b314a7d7e83270cedd5152ca9e628bf284f3 Mon Sep 17 00:00:00 2001 From: Blaise Taylor Date: Wed, 4 Feb 2026 09:52:34 -0500 Subject: [PATCH 2/2] AB#16 Removing test which invokes mapping.Equals(null);. Removing always true condition. --- .../Serialization/WorkflowMarkupSerializer.cs | 16 +++++++--------- .../WorkflowMarkupSerializerMappingTest.cs | 18 ------------------ 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs index d092838..b187d12 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/WorkflowMarkupSerializer.cs @@ -1401,16 +1401,14 @@ private void DeserializeCompoundProperty(WorkflowMarkupSerializationManager seri if (propValue != null && propValue.GetType() == typeof(string) && ((string)propValue).StartsWith("{}", StringComparison.Ordinal)) propValue = ((string)propValue).Substring(2); - if (property != null) + + try { - try - { - property.SetValue(obj, propValue, null); - } - catch - { - serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerComplexPropertySetFailed, new object[] { propertyName, propertyName, obj.GetType().Name }))); - } + property.SetValue(obj, propValue, null); + } + catch + { + serializationManager.ReportError(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_SerializerComplexPropertySetFailed, new object[] { propertyName, propertyName, obj.GetType().Name }))); } } } diff --git a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs index 2a9ce8d..7fe2203 100644 --- a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/WorkflowMarkupSerializerMappingTest.cs @@ -373,24 +373,6 @@ public void Equals_WithDifferentUnifiedAssemblyName_ReturnsFalse() Assert.False(result); } - [Fact] - [SuppressMessage("Style", "CA1062:Validate arguments of public methods", Justification = "Testing explicit null handling")] - public void Equals_WithNull_ReturnsFalse() - { - // Arrange - var mapping = new WorkflowMarkupSerializerMapping( - "prefix", - "http://test.namespace.com", - "TestNamespace", - "TestAssembly"); - - // Act - var result = mapping.Equals(null); - - // Assert - Assert.False(result); - } - [Fact] public void Equals_WithSameUnifiedAssemblyName_ReturnsTrue() {