From ee3a68645dc1ffc7293b444b8e69df9e192f2adc Mon Sep 17 00:00:00 2001 From: Blaise Taylor Date: Wed, 4 Mar 2026 10:54:34 -0500 Subject: [PATCH] AB#44 Medium and low severity Sonar recommendation. --- .github/workflows/ci.yml | 10 +++--- .github/workflows/release.yml | 12 ++++--- .../ComponentModel/AssemblyRef.cs | 2 +- .../Compiler/ValidationError.cs | 34 +++++-------------- .../Design/ColorMarkupSerializer.cs | 4 +-- .../ComponentModel/Design/Helpers.cs | 8 ++--- .../Design/PointMarkupSerializer.cs | 2 +- .../Design/SizeMarkupSerializer.cs | 2 +- .../CodeTypeReferenceSerializer.cs | 9 ++--- .../CollectionMarkupSerializer.cs | 8 ++--- .../DictionaryMarkupSerializer.cs | 19 +++++------ .../Serialization/XamlInterfaces.cs | 10 +++--- .../SynchronizationHandlesTypeConverter.cs | 4 +-- .../SR.cs | 22 ++++++------ .../CollectionMarkupSerializerTest.cs | 16 ++++----- .../DictionaryMarkupSerializerTest.cs | 1 - .../MarkupExtensionSerializerTest.cs | 2 +- 17 files changed, 72 insertions(+), 93 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b81d0c4..e6497f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,6 @@ on: pull_request: branches: [ master ] -permissions: - contents: read - packages: write - env: DOTNET_VERSION: "10.0.x" NODE_VERSION: "20" @@ -18,6 +14,9 @@ jobs: test: name: Test runs-on: ubuntu-latest + permissions: + contents: read + packages: read steps: - name: Checkout repository @@ -54,6 +53,9 @@ jobs: name: Publish to GitHub Packages runs-on: ubuntu-latest if: github.repository_owner == 'BpsLogicBuilder' + permissions: + contents: read + packages: write needs: test steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a96b1c..248aa7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,11 +4,6 @@ on: release: types: [published] -permissions: - contents: read - packages: write - id-token: write - env: DOTNET_VERSION: "10.0.x" NODE_VERSION: "20" @@ -17,6 +12,9 @@ jobs: test: name: Test runs-on: ubuntu-latest + permissions: + contents: read + packages: read steps: - name: Checkout repository @@ -53,6 +51,10 @@ jobs: name: Publish Package to GitHub Packages and NuGet.org runs-on: ubuntu-latest if: github.repository_owner == 'BpsLogicBuilder' + permissions: + contents: read + packages: write + id-token: write needs: test steps: diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/AssemblyRef.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/AssemblyRef.cs index 622a4a5..077ebd6 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/AssemblyRef.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/AssemblyRef.cs @@ -15,7 +15,7 @@ namespace LogicBuilder.Workflow.ComponentModel { - public class AssemblyRef + public static class AssemblyRef { public const string ActivitiesAssemblyRef = "LogicBuilder.Workflow.Activities.Rules, Version=2.0.0.0, Culture=neutral, PublicKeyToken=646893bec0268535"; public const string DialogAssemblyRef = "LogicBuilder.Workflow.Activities.Rules.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=646893bec0268535"; diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Compiler/ValidationError.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Compiler/ValidationError.cs index d8f4304..4971c14 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Compiler/ValidationError.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Compiler/ValidationError.cs @@ -5,13 +5,12 @@ namespace LogicBuilder.Workflow.ComponentModel.Compiler { [Serializable()] - public sealed class ValidationError + public sealed class ValidationError(string errorText, int errorNumber, bool isWarning, string propertyName) { - private readonly string errorText = string.Empty; - private readonly int errorNumber = 0; + private readonly string errorText = errorText; + private readonly int errorNumber = errorNumber; private Hashtable userData = null; - private readonly bool isWarning = false; - string propertyName = null; + private readonly bool isWarning = isWarning; public ValidationError(string errorText, int errorNumber) : this(errorText, errorNumber, false, null) @@ -23,24 +22,8 @@ public ValidationError(string errorText, int errorNumber, bool isWarning) { } - public ValidationError(string errorText, int errorNumber, bool isWarning, string propertyName) - { - this.errorText = errorText; - this.errorNumber = errorNumber; - this.isWarning = isWarning; - this.propertyName = propertyName; - } - public string PropertyName - { - get - { - return this.propertyName; - } - set - { - this.propertyName = value; - } - } + public string PropertyName { get; set; } = propertyName; + public string ErrorText { get @@ -66,15 +49,14 @@ public IDictionary UserData { get { - if (this.userData == null) - this.userData = new Hashtable(); + this.userData ??= []; return this.userData; } } public static ValidationError GetNotSetValidationError(string propertyName) { - ValidationError error = new ValidationError(SR.GetString(SR.Error_PropertyNotSet, propertyName), ErrorNumbers.Error_PropertyNotSet) + ValidationError error = new(SR.GetString(SR.Error_PropertyNotSet, propertyName), ErrorNumbers.Error_PropertyNotSet) { PropertyName = propertyName }; diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/ColorMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/ColorMarkupSerializer.cs index e9496f3..99b7dd4 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/ColorMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/ColorMarkupSerializer.cs @@ -30,12 +30,12 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa { if (propertyType.IsAssignableFrom(typeof(System.Drawing.Color))) { - string colorValue = value as string; + string colorValue = value; if (!String.IsNullOrEmpty(colorValue)) { if (colorValue.StartsWith("0X", StringComparison.OrdinalIgnoreCase)) { - long propertyValue = Convert.ToInt64((string)value, 16) & 0xFFFFFFFF; + long propertyValue = Convert.ToInt64(value, 16) & 0xFFFFFFFF; return System.Drawing.Color.FromArgb((Byte)(propertyValue >> 24), (Byte)(propertyValue >> 16), (Byte)(propertyValue >> 8), (Byte)(propertyValue)); } else diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs index be75625..7042cfb 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/Helpers.cs @@ -20,10 +20,10 @@ internal static XmlWriter CreateXmlWriter(object output) CloseOutput = true }; - if (output is string) - return XmlWriter.Create(output as string, settings); - else if (output is TextWriter) - return XmlWriter.Create(output as TextWriter, settings); + if (output is string outputString) + return XmlWriter.Create(outputString, settings); + else if (output is TextWriter outputTextWriter) + return XmlWriter.Create(outputTextWriter, settings); else { Debug.Assert(false, "Invalid argument type. 'output' must either be string or TextWriter."); diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/PointMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/PointMarkupSerializer.cs index b41b661..ff5d142 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/PointMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/PointMarkupSerializer.cs @@ -37,7 +37,7 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa { object point = Point.Empty; - string pointValue = value as string; + string pointValue = value; if (!String.IsNullOrWhiteSpace(pointValue)) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(Point)); diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/SizeMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/SizeMarkupSerializer.cs index 515eebf..395eda8 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/SizeMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Design/SizeMarkupSerializer.cs @@ -37,7 +37,7 @@ protected internal override object DeserializeFromString(WorkflowMarkupSerializa { object size = Size.Empty; - string sizeValue = value as string; + string sizeValue = value; if (!String.IsNullOrWhiteSpace(sizeValue)) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(Size)); diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CodeTypeReferenceSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CodeTypeReferenceSerializer.cs index e3a3282..799fa66 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CodeTypeReferenceSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CodeTypeReferenceSerializer.cs @@ -45,18 +45,13 @@ protected internal override string SerializeToString(WorkflowMarkupSerialization return typeName; } } - // - // If we get a real type make sure that we get the correct fully qualified name for the target framework version - string assemblyFullName = null; - + // If we didn't find an assembly value it is either a local type or something is wrong // However per the general guidance on multi-targeting it is up to the caller // to make sure that writers (such as Xoml) are given types that exist in the target framework // This makes it the job of the rules designer or rules validator to not call the Xoml stack // with types that do not exist in the target framework - return string.IsNullOrEmpty(assemblyFullName) - ? type.AssemblyQualifiedName - : string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.FullName, assemblyFullName); + return type.AssemblyQualifiedName; } protected internal override object DeserializeFromString(WorkflowMarkupSerializationManager serializationManager, Type propertyType, string value) diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CollectionMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CollectionMarkupSerializer.cs index 66f2c36..fa2efd9 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CollectionMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/CollectionMarkupSerializer.cs @@ -16,7 +16,7 @@ protected internal override IList GetChildren(WorkflowMarkupSerializationManager throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) - throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); + throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = obj as IEnumerable ?? Enumerable.Empty(); ArrayList arrayList = [.. enumerable]; @@ -34,7 +34,7 @@ protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializatio return false; if (!IsValidCollectionType(value.GetType())) - throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); + throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = (value as IEnumerable)?.OfType(); @@ -47,7 +47,7 @@ protected internal override void ClearChildren(WorkflowMarkupSerializationManage throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) - throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); + throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); if (obj is ICollection) /*Updating from collection == null - appears to be a bug e.g. List of T passes IsValidCollectionType and implements System.Collections.ICollection.*/ obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, [], CultureInfo.InvariantCulture); @@ -59,7 +59,7 @@ protected internal override void AddChild(WorkflowMarkupSerializationManager ser throw new ArgumentNullException(nameof(parentObject)); if (!IsValidCollectionType(parentObject.GetType())) - throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObject.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); + throw new InvalidOperationException(SR.GetString(SR.Error_SerializerTypeRequirement, parentObject.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); parentObject.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObject, [childObj], CultureInfo.InvariantCulture); } diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/DictionaryMarkupSerializer.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/DictionaryMarkupSerializer.cs index 4c650cf..52f7e6c 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/DictionaryMarkupSerializer.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/DictionaryMarkupSerializer.cs @@ -16,7 +16,7 @@ internal class DictionaryMarkupSerializer : WorkflowMarkupSerializer protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj) { IDictionary dictionary = obj as IDictionary ?? throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject)); - List childEntries = new List(); + List childEntries = []; foreach (DictionaryEntry dictionaryEntry in dictionary) { childEntries.Add(dictionaryEntry); @@ -29,7 +29,7 @@ protected internal override IList GetChildren(WorkflowMarkupSerializationManager protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj) { - return new PropertyInfo[] { }; + return []; } protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value) @@ -37,7 +37,7 @@ protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializatio if (value == null) return false; - if (!(value is IDictionary)) + if (value is not IDictionary) throw new InvalidOperationException(SR.GetString(SR.Error_DictionarySerializerNonDictionaryObject)); return (((IDictionary)value).Count > 0); @@ -115,33 +115,32 @@ protected internal override void OnAfterDeserialize(WorkflowMarkupSerializationM internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee) { - List extendedProperties = new List(); + List extendedProperties = []; DictionaryEntry? entry = null; if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null) entry = (DictionaryEntry)manager.WorkflowMarkupStack[typeof(DictionaryEntry)]; if (this.deserializingDictionary || (entry.HasValue && entry.Value.Value == extendee)) { ExtendedPropertyInfo extendedProperty = - new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance), + new(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance), new GetValueHandler(OnGetKeyValue), new SetValueHandler(OnSetKeyValue), new GetQualifiedNameHandler(OnGetXmlQualifiedName), manager); extendedProperties.Add(extendedProperty); } - return extendedProperties.ToArray(); + return [.. extendedProperties]; } - private object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee) + private static object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee) { DictionaryEntry? entry = null; if (extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null) entry = (DictionaryEntry)extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)]; - else - Debug.Assert(false, "Dictionary Entry not found in the WorkflowMarkupStack"); if (entry.HasValue && entry.Value.Value == extendee) return entry.Value.Key; + return null; } @@ -151,7 +150,7 @@ private void OnSetKeyValue(ExtendedPropertyInfo extendedProperty, object extende this.keylookupDictionary.Add(value, extendee); } - private XmlQualifiedName OnGetXmlQualifiedName(ExtendedPropertyInfo extendedProperty, WorkflowMarkupSerializationManager manager, out string prefix) + private static XmlQualifiedName OnGetXmlQualifiedName(ExtendedPropertyInfo extendedProperty, WorkflowMarkupSerializationManager manager, out string prefix) { prefix = StandardXomlKeys.Definitions_XmlNs_Prefix; return new XmlQualifiedName(extendedProperty.Name, StandardXomlKeys.Definitions_XmlNs); diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs index c47f32a..2aec9c2 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/Serialization/XamlInterfaces.cs @@ -89,7 +89,7 @@ public string ArgumentName } [ExcludeFromCodeCoverage] - public abstract class MarkupExtension + public abstract class MarkupExtension //NOSONAR { public abstract object ProvideValue(IServiceProvider provider); } @@ -116,11 +116,11 @@ public TypeExtension() { } public TypeExtension(string type) { - this.typeName = type ?? throw new ArgumentNullException("typeName"); + this.typeName = type ?? throw new ArgumentNullException(nameof(type)); } public TypeExtension(Type type) { - this.type = type ?? throw new ArgumentNullException("type"); + this.type = type ?? throw new ArgumentNullException(nameof(type)); } public override object ProvideValue(IServiceProvider provider) { @@ -128,10 +128,10 @@ public override object ProvideValue(IServiceProvider provider) return this.type; if (provider == null) - throw new ArgumentNullException("provider"); + throw new ArgumentNullException(nameof(provider)); if (this.typeName == null) - throw new InvalidOperationException("typename"); + throw new InvalidOperationException(nameof(typeName)); WorkflowMarkupSerializationManager manager = provider as WorkflowMarkupSerializationManager ?? throw new ArgumentNullException("provider"); if (manager.WorkflowMarkupStack[typeof(XmlReader)] is not XmlReader reader) diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/SynchronizationHandlesTypeConverter.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/SynchronizationHandlesTypeConverter.cs index 85bf8a3..cd23a61 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/SynchronizationHandlesTypeConverter.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/ComponentModel/SynchronizationHandlesTypeConverter.cs @@ -34,8 +34,8 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - if (value is string) - return UnStringify(value as string); + if (value is string stringValue) + return UnStringify(stringValue); return base.ConvertFrom(context, culture, value); } diff --git a/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs b/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs index 9ac5a39..58d4d3e 100644 --- a/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs +++ b/LogicBuilder.Workflow.ComponentModel.Serialization/SR.cs @@ -1,10 +1,11 @@ using System; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; using System.Resources; +namespace LogicBuilder.Workflow; + [AttributeUsage(AttributeTargets.All)] internal sealed class SRDescriptionAttribute : DescriptionAttribute { @@ -15,9 +16,9 @@ public SRDescriptionAttribute(string description) public SRDescriptionAttribute(string description, string resourceSet) { - ResourceManager rm = new ResourceManager(resourceSet, Assembly.GetExecutingAssembly()); + ResourceManager rm = new(resourceSet, Assembly.GetExecutingAssembly()); DescriptionValue = rm.GetString(description); - System.Diagnostics.Debug.Assert(DescriptionValue != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { description })); + System.Diagnostics.Debug.Assert(DescriptionValue != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", description)); } } @@ -41,9 +42,9 @@ protected override string GetLocalizedString(string value) { if (this.resourceSet.Length > 0) { - ResourceManager rm = new ResourceManager(resourceSet, Assembly.GetExecutingAssembly()); + ResourceManager rm = new(resourceSet, Assembly.GetExecutingAssembly()); String localizedString = rm.GetString(value); - System.Diagnostics.Debug.Assert(localizedString != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { value })); + System.Diagnostics.Debug.Assert(localizedString != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", value)); return localizedString; } else @@ -63,9 +64,9 @@ public SRDisplayNameAttribute(string name) public SRDisplayNameAttribute(string name, string resourceSet) { - ResourceManager rm = new ResourceManager(resourceSet, Assembly.GetExecutingAssembly()); + ResourceManager rm = new(resourceSet, Assembly.GetExecutingAssembly()); DisplayNameValue = rm.GetString(name); - System.Diagnostics.Debug.Assert(DisplayNameValue != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name })); + System.Diagnostics.Debug.Assert(DisplayNameValue != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", name)); } } @@ -86,8 +87,7 @@ internal SR() private static SR GetLoader() { - if (loader == null) - loader = new SR(); + loader ??= new SR(); return loader; } @@ -107,7 +107,7 @@ internal static string GetString(CultureInfo culture, string name, params object { SR sys = GetLoader(); string res = sys.resources.GetString(name, culture); - System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name })); + System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", name)); return args != null && args.Length > 0 ? string.Format(CultureInfo.CurrentCulture, res, args) : res; @@ -122,7 +122,7 @@ internal static string GetString(CultureInfo culture, string name) { SR sys = GetLoader(); string res = sys.resources.GetString(name, culture); - System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", new object[] { name })); + System.Diagnostics.Debug.Assert(res != null, string.Format(CultureInfo.CurrentCulture, "String resource {0} not found.", name)); return res; } diff --git a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/CollectionMarkupSerializerTest.cs b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/CollectionMarkupSerializerTest.cs index 1101d94..998e888 100644 --- a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/CollectionMarkupSerializerTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/CollectionMarkupSerializerTest.cs @@ -36,7 +36,7 @@ public void GetChildren_ThrowsException_WhenObjectIsNotValidCollectionType() var invalidObject = "not a collection"; // Act & Assert - var exception = Assert.Throws(() => _serializer.GetChildren(_serializationManager, invalidObject)); + var exception = Assert.Throws(() => _serializer.GetChildren(_serializationManager, invalidObject)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -49,7 +49,7 @@ public void GetChildren_ThrowsException_WhenObjectIsArray() var array = new int[] { 1, 2, 3 }; // Act & Assert - var exception = Assert.Throws(() => _serializer.GetChildren(_serializationManager, array)); + var exception = Assert.Throws(() => _serializer.GetChildren(_serializationManager, array)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -142,7 +142,7 @@ public void ShouldSerializeValue_ThrowsException_WhenValueIsNotValidCollectionTy var invalidValue = "not a collection"; // Act & Assert - var exception = Assert.Throws(() => _serializer.ShouldSerializeValue(_serializationManager, invalidValue)); + var exception = Assert.Throws(() => _serializer.ShouldSerializeValue(_serializationManager, invalidValue)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -155,7 +155,7 @@ public void ShouldSerializeValue_ThrowsException_WhenValueIsArray() var array = new int[] { 1, 2, 3 }; // Act & Assert - var exception = Assert.Throws(() => _serializer.ShouldSerializeValue(_serializationManager, array)); + var exception = Assert.Throws(() => _serializer.ShouldSerializeValue(_serializationManager, array)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -205,7 +205,7 @@ public void ClearChildren_ThrowsException_WhenObjectIsNotValidCollectionType() var invalidObject = "not a collection"; // Act & Assert - var exception = Assert.Throws(() => _serializer.ClearChildren(_serializationManager, invalidObject)); + var exception = Assert.Throws(() => _serializer.ClearChildren(_serializationManager, invalidObject)); Assert.Contains("in order to be serialized as a Collection", exception.Message); } @@ -216,7 +216,7 @@ public void ClearChildren_ThrowsException_WhenObjectIsArray() var array = new int[] { 1, 2, 3 }; // Act & Assert - var exception = Assert.Throws(() => _serializer.ClearChildren(_serializationManager, array)); + var exception = Assert.Throws(() => _serializer.ClearChildren(_serializationManager, array)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -270,7 +270,7 @@ public void AddChild_ThrowsException_WhenParentObjectIsNotValidCollectionType() var childObj = "child"; // Act & Assert - var exception = Assert.Throws(() => _serializer.AddChild(_serializationManager, invalidParent, childObj)); + var exception = Assert.Throws(() => _serializer.AddChild(_serializationManager, invalidParent, childObj)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); @@ -284,7 +284,7 @@ public void AddChild_ThrowsException_WhenParentObjectIsArray() var childObj = 4; // Act & Assert - var exception = Assert.Throws(() => _serializer.AddChild(_serializationManager, array, childObj)); + var exception = Assert.Throws(() => _serializer.AddChild(_serializationManager, array, childObj)); Assert.Contains("The object of type", exception.Message); Assert.Contains("needs to implement", exception.Message); Assert.Contains("in order to be serialized as a Collection", exception.Message); diff --git a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/DictionaryMarkupSerializerTest.cs b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/DictionaryMarkupSerializerTest.cs index dab96dc..d1b4202 100644 --- a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/DictionaryMarkupSerializerTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/DictionaryMarkupSerializerTest.cs @@ -738,7 +738,6 @@ public void GetExtendedProperties_ReturnsEmpty_WhenEntryValueDoesNotMatch() public void OnGetKeyValue_ReturnsNull_WhenEntryNotInStack() { // Arrange - Trace.Listeners.Clear(); var dictionary = new Dictionary(); var extendee = "testValue"; diff --git a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/MarkupExtensionSerializerTest.cs b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/MarkupExtensionSerializerTest.cs index 9be5e89..b9a9fd2 100644 --- a/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/MarkupExtensionSerializerTest.cs +++ b/Workflow.ComponentModel.Serialization.Tests/ComponentModel/Serialization/MarkupExtensionSerializerTest.cs @@ -104,7 +104,7 @@ public void SerializeToString_ThrowsArgumentNullException_WhenValueIsNull() } } - private sealed class WellKnownTypeSerializationProvider : IDesignerSerializationProvider + private sealed class WellKnownTypeSerializationProvider : IDesignerSerializationProvider //NOSONAR - used on line 33 of this file. { #region IDesignerSerializationProvider Members object? IDesignerSerializationProvider.GetSerializer(IDesignerSerializationManager manager, object? currentSerializer, Type? objectType, Type serializerType)