From 2288bb0f7bcdcd65e86aff4f5c77afc136c05494 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 13:07:14 +0100 Subject: [PATCH 01/11] :boom: remove deprecated datapair collections --- .../Collections/DataPairCollection.cs | 41 ------------------- .../Collections/DataPairDictionary.cs | 41 ------------------- 2 files changed, 82 deletions(-) delete mode 100644 src/Cuemon.Core/Collections/DataPairCollection.cs delete mode 100644 src/Cuemon.Core/Collections/DataPairDictionary.cs diff --git a/src/Cuemon.Core/Collections/DataPairCollection.cs b/src/Cuemon.Core/Collections/DataPairCollection.cs deleted file mode 100644 index a266ba63d..000000000 --- a/src/Cuemon.Core/Collections/DataPairCollection.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.ObjectModel; - -namespace Cuemon.Collections -{ - /// - /// Provides a collection of . - /// - public class DataPairCollection : Collection - { - /// - /// Initializes a new instance of the class. - /// - public DataPairCollection() : base() - { - } - - /// - /// Adds a new to the end of this . - /// - /// The type of the data being added to this instance. - /// The name of the data pair. - /// The value of the data pair. - public void Add(string name, T value) - { - Add(name, value, typeof(T)); - } - - /// - /// Adds a new to the end of this . - /// - /// The type of the data being added to this instance. - /// The name of the data pair. - /// The value of the data pair. - /// The type of the data pair. - public void Add(string name, T value, Type typeOf) - { - base.Add(new DataPair(name, value, typeOf)); - } - } -} \ No newline at end of file diff --git a/src/Cuemon.Core/Collections/DataPairDictionary.cs b/src/Cuemon.Core/Collections/DataPairDictionary.cs deleted file mode 100644 index 16f0a245c..000000000 --- a/src/Cuemon.Core/Collections/DataPairDictionary.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Cuemon.Collections -{ - /// - /// Provides a collection of . - /// - public class DataPairDictionary : Dictionary - { - /// - /// Initializes a new instance of the class. - /// - public DataPairDictionary() : base() - { - } - - /// - /// Adds a new to the end of this . - /// - /// The type of the data being added to this instance. - /// The name of the data pair. - /// The value of the data pair. - public void Add(string name, T value) - { - Add(name, value, typeof(T)); - } - - /// - /// Adds a new to the end of this . - /// - /// The type of the data being added to this instance. - /// The name of the data pair. - /// The value of the data pair. - /// The type of the data pair. - public void Add(string name, T value, Type typeOf) - { - base.Add(name, new DataPair(name, value, typeOf)); - } - } -} \ No newline at end of file From f725a0a05a7d02f7b91e4b5e30f87438dbe7f101 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 13:07:33 +0100 Subject: [PATCH 02/11] :boom: remove deprecated initializer types --- src/Cuemon.Core/Initializer.cs | 19 -------- src/Cuemon.Core/InitializerBuilder.cs | 68 --------------------------- 2 files changed, 87 deletions(-) delete mode 100644 src/Cuemon.Core/Initializer.cs delete mode 100644 src/Cuemon.Core/InitializerBuilder.cs diff --git a/src/Cuemon.Core/Initializer.cs b/src/Cuemon.Core/Initializer.cs deleted file mode 100644 index a7ab049f4..000000000 --- a/src/Cuemon.Core/Initializer.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Cuemon -{ - /// - /// Provides a generic way to wrap and initialize a class for countless scenarios. - /// - public static class Initializer - { - /// - /// Creates a new instance of the wrapping the specified . - /// - /// The type of object to wrap. - /// The instance to initialize within a protective wrapping. - /// A new instance of with the specified wrapped. - public static InitializerBuilder Create(T instance) where T : class - { - return new InitializerBuilder(instance); - } - } -} \ No newline at end of file diff --git a/src/Cuemon.Core/InitializerBuilder.cs b/src/Cuemon.Core/InitializerBuilder.cs deleted file mode 100644 index 9aed3fd8f..000000000 --- a/src/Cuemon.Core/InitializerBuilder.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; - -namespace Cuemon -{ - /// - /// Supports the for building custom initializers. - /// - /// The type of object to wrap. - public class InitializerBuilder where T : class - { - /// - /// Initializes a new instance of the class. - /// - /// The instance to initialize within a protective wrapping. - internal InitializerBuilder(T instance) - { - Validator.ThrowIfNull(instance); - Instance = instance; - } - - /// - /// Gets the initialized instance. - /// - /// The initialized instance. - public T Instance { get; } - - /// - /// Ignores any that might be thrown by instance . - /// - /// The delegate that will continue initializing instance while ignoring any . - /// A reference to this instance. - public InitializerBuilder IgnoreMissingMethod(Action initializer) - { - return Ignore(initializer, ex => ex is MissingMethodException); - } - - /// - /// Ignores any exceptions that might be thrown by instance . - /// - /// The delegate that will continue initializing instance while ignoring any exceptions. - /// A reference to this instance. - public InitializerBuilder IgnoreAny(Action initializer) - { - return Ignore(initializer, ex => true); - } - - /// - /// Ignores exceptions thrown by instance that is specified by the function delegate . - /// - /// The delegate that will continue initializing instance while ignoring any exceptions specified by . - /// The function delegate that will parse thrown exceptions and ignore those specified. - /// A reference to this instance. - public InitializerBuilder Ignore(Action initializer, Func ignorer) - { - Validator.ThrowIfNull(ignorer); - Validator.ThrowIfNull(initializer); - try - { - initializer(Instance); - } - catch (Exception ex) - { - if (!ignorer(ex)) { throw; } - } - return this; - } - } -} \ No newline at end of file From b29969967bfd77a9e44a21da83fff93bcf80d0ce Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 13:07:44 +0100 Subject: [PATCH 03/11] :boom: remove deprecated mapping types --- src/Cuemon.Core/IndexMapping.cs | 68 ------------------ src/Cuemon.Core/Mapping.cs | 31 -------- .../MappingExtensions.cs | 58 --------------- .../MappingExtensionsTest.cs | 71 ------------------- 4 files changed, 228 deletions(-) delete mode 100644 src/Cuemon.Core/IndexMapping.cs delete mode 100644 src/Cuemon.Core/Mapping.cs delete mode 100644 src/Cuemon.Extensions.Core/MappingExtensions.cs delete mode 100644 test/Cuemon.Extensions.Core.Tests/MappingExtensionsTest.cs diff --git a/src/Cuemon.Core/IndexMapping.cs b/src/Cuemon.Core/IndexMapping.cs deleted file mode 100644 index 482f131bd..000000000 --- a/src/Cuemon.Core/IndexMapping.cs +++ /dev/null @@ -1,68 +0,0 @@ -namespace Cuemon -{ - /// - /// Defines the mapping between a column/field/item in a data source and a column/field/item in the data destination. This class cannot be inherited. - /// - public sealed class IndexMapping : Mapping - { - /// - /// Initializes a new instance of the class. - /// - /// The name of the source column/field/item within the data source. - /// The name of the destination column/field/item within the data destination. - public IndexMapping(string source, string destination) : base(source, destination) - { - SourceIndex = -1; - DestinationIndex = -1; - } - - /// - /// Initializes a new instance of the class. - /// - /// The name of the source column/field/item within the data source. - /// The ordinal position of the destination column/field/item within the data destination. - public IndexMapping(string source, int destinationIndex) : base(source, "") - { - Validator.ThrowIfLowerThan(destinationIndex, 0, nameof(destinationIndex)); - SourceIndex = -1; - DestinationIndex = destinationIndex; - } - - /// - /// Initializes a new instance of the class. - /// - /// The ordinal position of the source column/field/item within the data source. - /// The name of the destination column/field/item within the data destination. - public IndexMapping(int sourceIndex, string destination) : base("", destination) - { - Validator.ThrowIfLowerThan(sourceIndex, 0, nameof(sourceIndex)); - SourceIndex = sourceIndex; - DestinationIndex = -1; - } - - /// - /// Initializes a new instance of the class. - /// - /// The ordinal position of the source column/field/item within the data source. - /// The ordinal position of the destination column/field/item within the data destination. - public IndexMapping(int sourceIndex, int destinationIndex) : base("", "") - { - Validator.ThrowIfLowerThan(sourceIndex, 0, nameof(sourceIndex)); - Validator.ThrowIfLowerThan(destinationIndex, 0, nameof(destinationIndex)); - SourceIndex = sourceIndex; - DestinationIndex = destinationIndex; - } - - /// - /// Gets the ordinal position of the column/field/item within the data source. - /// - /// The integer value of the column/field/item within the data source. - public int SourceIndex { get; private set; } - - /// - /// Gets the ordinal position of the column/field/item within the data destination. - /// - /// The integer value of the column/field/item within the data destination. - public int DestinationIndex { get; private set; } - } -} \ No newline at end of file diff --git a/src/Cuemon.Core/Mapping.cs b/src/Cuemon.Core/Mapping.cs deleted file mode 100644 index d37c2c72b..000000000 --- a/src/Cuemon.Core/Mapping.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Cuemon -{ - /// - /// Defines the mapping between a column/field/item in a data source and a column/field/item in the data destination. - /// - public class Mapping - { - /// - /// Initializes a new instance of the class. - /// - /// The name of the source column/field/item within the data source. - /// The name of the destination column/field/item within the data destination. - public Mapping(string source, string destination) - { - Source = source; - Destination = destination; - } - - /// - /// Gets the name of the column/field/item being mapped in the data source. - /// - /// The string value of the column/field/item being mapped in the data source. - public string Source { get; private set; } - - /// - /// Get the name of the column/field/item being mapped in the data destination. - /// - /// The string value of the column/field/item being mapped in the data destination. - public string Destination { get; private set; } - } -} \ No newline at end of file diff --git a/src/Cuemon.Extensions.Core/MappingExtensions.cs b/src/Cuemon.Extensions.Core/MappingExtensions.cs deleted file mode 100644 index c870109b8..000000000 --- a/src/Cuemon.Extensions.Core/MappingExtensions.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Collections.Generic; - -namespace Cuemon.Extensions -{ - /// - /// Extension methods for the class. - /// - public static class MappingExtensions - { - /// - /// Creates a new using column/field/item names to refer to a and a which is added to the specified of mappings. - /// - /// A collection of elements. - /// The name of the column/field/item within the data source. - /// The name of the destination column/field/item within the data destination. - public static void AddMapping(this ICollection collection, string source, string destination) - { - Validator.ThrowIfNull(collection); - collection.Add(new Mapping(source, destination)); - } - - /// - /// Creates a new using an ordinal for the and a column/field/item name to describe the which is added to the specified of mappings. - /// - /// A collection of elements. - /// The ordinal position of the source column/field/item within the data source. - /// The name of the destination column/field/item within the data destination. - public static void AddMapping(this ICollection collection, int sourceIndex, string destination) - { - Validator.ThrowIfNull(collection); - collection.Add(new IndexMapping(sourceIndex, destination)); - } - - /// - /// Creates a new using a column/field/item name to describe the and an ordinal to specify the which is added to the specified of mappings. - /// - /// A collection of elements. - /// The name of the column/field/item within the data source. - /// The ordinal position of the destination column/field/item within the data destination. - public static void AddMapping(this ICollection collection, string source, int destinationIndex) - { - Validator.ThrowIfNull(collection); - collection.Add(new IndexMapping(source, destinationIndex)); - } - - /// - /// Creates a new using ordinals to specify both and columns/fields/items which is added to the specified of mappings. - /// - /// A collection of elements. - /// The ordinal position of the source column/field/item within the data source. - /// The ordinal position of the destination column/field/item within the data destination. - public static void AddMapping(this ICollection collection, int sourceIndex, int destinationIndex) - { - Validator.ThrowIfNull(collection); - collection.Add(new IndexMapping(sourceIndex, destinationIndex)); - } - } -} \ No newline at end of file diff --git a/test/Cuemon.Extensions.Core.Tests/MappingExtensionsTest.cs b/test/Cuemon.Extensions.Core.Tests/MappingExtensionsTest.cs deleted file mode 100644 index ec4ac0a54..000000000 --- a/test/Cuemon.Extensions.Core.Tests/MappingExtensionsTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Codebelt.Extensions.Xunit; -using Xunit; -using Xunit.Abstractions; - -namespace Cuemon.Extensions -{ - public class MappingExtensionsTest : Test - { - public MappingExtensionsTest(ITestOutputHelper output) : base(output) - { - } - - [Fact] - public void Add_ShouldAddMappingWithStringValues() - { - var sut1 = new List(); - var sut2 = new List(sut1); - var sut3 = new Mapping("Source", "Destination"); - sut2.AddMapping("Source", "Destination"); - - Assert.Empty(sut1); - Assert.Equal(1, sut2.Count); - Assert.Equal(sut3.Source, sut2.Single().Source); - Assert.Equal(sut3.Destination, sut2.Single().Destination); - } - - [Fact] - public void Add_ShouldAddIndexMappingWithOrdinalAndString() - { - var sut1 = new List(); - var sut2 = new List(sut1); - var sut3 = new IndexMapping(42, "Destination"); - sut2.AddMapping(42, "Destination"); - - Assert.Empty(sut1); - Assert.Equal(1, sut2.Count); - Assert.Equal(sut3.SourceIndex, sut2.Single().As().SourceIndex); - Assert.Equal(sut3.Destination, sut2.Single().Destination); - } - - [Fact] - public void Add_ShouldAddIndexMappingWithStringAndOrdinal() - { - var sut1 = new List(); - var sut2 = new List(sut1); - var sut3 = new IndexMapping("Source", 42); - sut2.AddMapping("Source", 42); - - Assert.Empty(sut1); - Assert.Equal(1, sut2.Count); - Assert.Equal(sut3.Source, sut2.Single().Source); - Assert.Equal(sut3.DestinationIndex, sut2.Single().As().DestinationIndex); - } - - [Fact] - public void Add_ShouldAddIndexMappingWithOrdinals() - { - var sut1 = new List(); - var sut2 = new List(sut1); - var sut3 = new IndexMapping(24, 42); - sut2.AddMapping(24, 42); - - Assert.Empty(sut1); - Assert.Equal(1, sut2.Count); - Assert.Equal(sut3.SourceIndex, sut2.Single().As().SourceIndex); - Assert.Equal(sut3.DestinationIndex, sut2.Single().As().DestinationIndex); - } - } -} \ No newline at end of file From 2442ed79d5e339b3a9225412d3e5da5d951c6971 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 13:16:57 +0100 Subject: [PATCH 04/11] :boom: remove deprecated horizontal types --- src/Cuemon.Core/HorizontalDirection.cs | 17 ----------------- .../JsonConverterCollectionExtensionsTest.cs | 12 ++++++------ 2 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 src/Cuemon.Core/HorizontalDirection.cs diff --git a/src/Cuemon.Core/HorizontalDirection.cs b/src/Cuemon.Core/HorizontalDirection.cs deleted file mode 100644 index 5abb56ef0..000000000 --- a/src/Cuemon.Core/HorizontalDirection.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Cuemon -{ - /// - /// Specifies a set of values defining a horizontal direction. - /// - public enum HorizontalDirection - { - /// - /// Indicates a vertical direction of Left. - /// - Left, - /// - /// Indicates a vertical direction of Right. - /// - Right - } -} \ No newline at end of file diff --git a/test/Cuemon.Extensions.Text.Json.Tests/Converters/JsonConverterCollectionExtensionsTest.cs b/test/Cuemon.Extensions.Text.Json.Tests/Converters/JsonConverterCollectionExtensionsTest.cs index 41bda0b80..349b9cb4e 100644 --- a/test/Cuemon.Extensions.Text.Json.Tests/Converters/JsonConverterCollectionExtensionsTest.cs +++ b/test/Cuemon.Extensions.Text.Json.Tests/Converters/JsonConverterCollectionExtensionsTest.cs @@ -18,7 +18,7 @@ public JsonConverterCollectionExtensionsTest(ITestOutputHelper output) : base(ou [Fact] public void AddStringEnumConverter_ShouldAddStringEnumConverterToConverterCollection_WithPascalCase() { - var sut1 = HorizontalDirection.Left; + var sut1 = DayOfWeek.Friday; var sut2 = new JsonFormatterOptions(); sut2.Settings.PropertyNamingPolicy = null; // set PascalCase sut2.Settings.Converters.Clear(); @@ -32,8 +32,8 @@ public void AddStringEnumConverter_ShouldAddStringEnumConverterToConverterCollec var json = result.ToEncodedString(); - Assert.True(jc.CanConvert(typeof(HorizontalDirection))); - Assert.Equal("\"Left\"", json); + Assert.True(jc.CanConvert(typeof(DayOfWeek))); + Assert.Equal("\"Friday\"", json); TestOutput.WriteLine(json); }); @@ -73,7 +73,7 @@ public void AddStringFlagsEnumConverter_ShouldAddStringFlagsEnumConverterToConve [Fact] public void AddStringEnumConverter_ShouldAddStringEnumConverterToConverterCollection() { - var sut1 = HorizontalDirection.Left; + var sut1 = DayOfWeek.Friday; var sut2 = new JsonFormatterOptions(); sut2.Settings.Converters.Clear(); sut2.Settings.Converters.AddStringEnumConverter(); @@ -86,8 +86,8 @@ public void AddStringEnumConverter_ShouldAddStringEnumConverterToConverterCollec var json = result.ToEncodedString(); - Assert.True(jc.CanConvert(typeof(HorizontalDirection))); - Assert.Equal("\"left\"", json); + Assert.True(jc.CanConvert(typeof(DayOfWeek))); + Assert.Equal("\"friday\"", json); TestOutput.WriteLine(json); }); From f25318050655ffbd69dcebfb0aa83be2eace81cb Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 13:17:34 +0100 Subject: [PATCH 05/11] :truck: move verticaldirection type to Cuemon.Extensions --- .../VerticalDirection.cs | 4 ++-- test/Cuemon.Core.Tests/Text/ParserFactoryTest.cs | 1 + test/Cuemon.Core.Tests/ValidatorTest.cs | 1 + .../UnkeyedHashFactoryTest.cs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) rename src/{Cuemon.Core => Cuemon.Extensions.Core}/VerticalDirection.cs (91%) diff --git a/src/Cuemon.Core/VerticalDirection.cs b/src/Cuemon.Extensions.Core/VerticalDirection.cs similarity index 91% rename from src/Cuemon.Core/VerticalDirection.cs rename to src/Cuemon.Extensions.Core/VerticalDirection.cs index 7c49e010f..ee131a851 100644 --- a/src/Cuemon.Core/VerticalDirection.cs +++ b/src/Cuemon.Extensions.Core/VerticalDirection.cs @@ -1,4 +1,4 @@ -namespace Cuemon +namespace Cuemon.Extensions { /// /// Specifies a set of values defining a vertical direction. @@ -14,4 +14,4 @@ public enum VerticalDirection /// Up } -} \ No newline at end of file +} diff --git a/test/Cuemon.Core.Tests/Text/ParserFactoryTest.cs b/test/Cuemon.Core.Tests/Text/ParserFactoryTest.cs index 2d26445ad..03b39043e 100644 --- a/test/Cuemon.Core.Tests/Text/ParserFactoryTest.cs +++ b/test/Cuemon.Core.Tests/Text/ParserFactoryTest.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Globalization; using Codebelt.Extensions.Xunit; +using Cuemon.Extensions; using Xunit; using Xunit.Abstractions; diff --git a/test/Cuemon.Core.Tests/ValidatorTest.cs b/test/Cuemon.Core.Tests/ValidatorTest.cs index 5038e7cd3..5bdf1d75f 100644 --- a/test/Cuemon.Core.Tests/ValidatorTest.cs +++ b/test/Cuemon.Core.Tests/ValidatorTest.cs @@ -8,6 +8,7 @@ using Cuemon.Extensions; #endif using Codebelt.Extensions.Xunit; +using Cuemon.Extensions; using Xunit; using Xunit.Abstractions; diff --git a/test/Cuemon.Security.Cryptography.Tests/UnkeyedHashFactoryTest.cs b/test/Cuemon.Security.Cryptography.Tests/UnkeyedHashFactoryTest.cs index 8b0646ad3..aa72f9f5a 100644 --- a/test/Cuemon.Security.Cryptography.Tests/UnkeyedHashFactoryTest.cs +++ b/test/Cuemon.Security.Cryptography.Tests/UnkeyedHashFactoryTest.cs @@ -26,7 +26,7 @@ public void CreateCryptoSha384_ShouldBeValidHashResult() var h = UnkeyedHashFactory.CreateCryptoSha384(); Assert.Equal("1761336e3f7cbfe51deb137f026f89e01a448e3b1fafa64039c1464ee8732f11a5341a6f41e0c202294736ed64db1a84", h.ComputeHash(Alphanumeric.LettersAndNumbers).ToHexadecimalString()); Assert.Equal("90ae531f24e48697904a4d0286f354c50a350ebb6c2b9efcb22f71c96ceaeffc11c6095e9ca0df0ec30bf685dcf2e5e5", h.ComputeHash(Alphanumeric.Numbers).ToHexadecimalString()); - Assert.Equal("7210af19145ec2a8e250a7fe8e9eeeac1301e524daab82366c36be614dc35402a289101e48cad61c45337f2f32c14fdc", h.ComputeHash(VerticalDirection.Up).ToHexadecimalString()); + Assert.Equal("d3b3f28933c5c91daa6a355aef5e09252e9c78baf751db717a2fde4b88e962a55e740acd869a3057b6020ad68e650a5f", h.ComputeHash(DayOfWeek.Friday).ToHexadecimalString()); } [Fact] From 185c738c4e45f15df3fd73fc11e9fe56e8cd5290 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 15:31:38 +0100 Subject: [PATCH 06/11] :truck: move Wrapper types to Cuemon.Extensions --- src/{Cuemon.Core => Cuemon.Extensions.Core}/IWrapper.cs | 8 ++------ src/{Cuemon.Core => Cuemon.Extensions.Core}/Wrapper.cs | 9 +-------- src/Cuemon.Xml/Serialization/XmlWrapper.cs | 1 + 3 files changed, 4 insertions(+), 14 deletions(-) rename src/{Cuemon.Core => Cuemon.Extensions.Core}/IWrapper.cs (95%) rename src/{Cuemon.Core => Cuemon.Extensions.Core}/Wrapper.cs (98%) diff --git a/src/Cuemon.Core/IWrapper.cs b/src/Cuemon.Extensions.Core/IWrapper.cs similarity index 95% rename from src/Cuemon.Core/IWrapper.cs rename to src/Cuemon.Extensions.Core/IWrapper.cs index a77f0df29..5622c90e8 100644 --- a/src/Cuemon.Core/IWrapper.cs +++ b/src/Cuemon.Extensions.Core/IWrapper.cs @@ -1,7 +1,7 @@ using System; using System.Reflection; -namespace Cuemon +namespace Cuemon.Extensions { /// /// Provides a generic way to wrap an object instance of inside another object. @@ -9,7 +9,6 @@ namespace Cuemon /// The type of the object instance to wrap inside another object. public interface IWrapper : IData { - #region Properties /// /// Gets the instance of the object. /// @@ -33,9 +32,7 @@ public interface IWrapper : IData /// /// true if this instance has a member reference; otherwise, false. bool HasMemberReference { get; } - #endregion - #region Methods /// /// Returns a value that is equivalent to the instance of the node that this hierarchical structure represents. /// @@ -50,6 +47,5 @@ public interface IWrapper : IData /// An object that supplies culture-specific formatting information. /// A value that is equivalent to the instance of the node that this hierarchical structure represents. TResult InstanceAs(IFormatProvider provider); - #endregion } -} \ No newline at end of file +} diff --git a/src/Cuemon.Core/Wrapper.cs b/src/Cuemon.Extensions.Core/Wrapper.cs similarity index 98% rename from src/Cuemon.Core/Wrapper.cs rename to src/Cuemon.Extensions.Core/Wrapper.cs index 4d5e9f237..ad13b6fb8 100644 --- a/src/Cuemon.Core/Wrapper.cs +++ b/src/Cuemon.Extensions.Core/Wrapper.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.Reflection; -namespace Cuemon +namespace Cuemon.Extensions { /// /// Provides helper method for a object. @@ -84,7 +84,6 @@ public class Wrapper : IWrapper private Type _instanceType; private MemberInfo _memberReference; - #region Constructors /// /// Initializes a new instance of the class. /// @@ -103,9 +102,7 @@ public Wrapper(T instance, MemberInfo memberReference = null) _instanceType = instance.GetType(); _memberReference = memberReference; } - #endregion - #region Properties /// /// Gets the object that this wrapper represents. /// @@ -148,9 +145,6 @@ public virtual MemberInfo MemberReference /// An object that implements the interface and contains a collection of user-defined key/value pairs. public virtual IDictionary Data { get; } = new Dictionary(); - #endregion - - #region Methods /// /// Returns a value that is equivalent to the instance of the object that this wrapper represents. /// @@ -199,6 +193,5 @@ public override string ToString() { return Wrapper.ParseInstance(this); } - #endregion } } diff --git a/src/Cuemon.Xml/Serialization/XmlWrapper.cs b/src/Cuemon.Xml/Serialization/XmlWrapper.cs index ed87c3daf..104bfa528 100644 --- a/src/Cuemon.Xml/Serialization/XmlWrapper.cs +++ b/src/Cuemon.Xml/Serialization/XmlWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Reflection; using System.Xml.Serialization; +using Cuemon.Extensions; namespace Cuemon.Xml.Serialization { From 3413bc42af37c7d3a69d8b7af3ce4c0488199e6c Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 15:37:59 +0100 Subject: [PATCH 07/11] :truck: move Hierarchy related types to Cuemon.Extensions --- .../ExceptionDecoratorExtensions.cs | 4 +- .../Extensions/ObjectDecoratorExtensions.cs | 44 ++++++++++++ .../Extensions/TypeDecoratorExtensions.cs | 2 +- src/Cuemon.Core/Infrastructure.cs | 12 ---- src/Cuemon.Core/ObjectPortrayalOptions.cs | 2 +- src/Cuemon.Data.SqlClient/SqlDataManager.cs | 2 +- .../Runtime}/Hierarchy.cs | 38 +++------- .../Runtime}/HierarchyDecoratorExtensions.cs | 40 +++++------ .../Runtime/HierarchyOptions.cs} | 13 ++-- .../Runtime}/IHierarchy.cs | 8 +-- .../Serialization/HierarchySerializer.cs | 7 +- .../JsonReaderExtensions.cs | 72 ------------------- .../HierarchyExtensions.cs | 3 +- .../XmlReaderExtensions.cs | 1 + src/Cuemon.Xml/Cuemon.Xml.csproj | 3 +- .../HierarchyDecoratorExtensions.cs | 1 + .../XmlConverterDecoratorExtensions.cs | 1 + .../XmlReaderDecoratorExtensions.cs | 1 + .../XmlWriterDecoratorExtensions.cs | 3 +- .../Converters/DefaultXmlConverter.cs | 2 + .../Serialization/HierarchySerializerTest.cs | 1 + .../XmlReaderExtensionsTest.cs | 3 +- 22 files changed, 106 insertions(+), 157 deletions(-) delete mode 100644 src/Cuemon.Core/Infrastructure.cs rename src/{Cuemon.Core => Cuemon.Extensions.Core/Runtime}/Hierarchy.cs (92%) rename src/{Cuemon.Core/Extensions => Cuemon.Extensions.Core/Runtime}/HierarchyDecoratorExtensions.cs (94%) rename src/{Cuemon.Core/Reflection/ObjectHierarchyOptions.cs => Cuemon.Extensions.Core/Runtime/HierarchyOptions.cs} (94%) rename src/{Cuemon.Core => Cuemon.Extensions.Core/Runtime}/IHierarchy.cs (97%) rename src/{Cuemon.Core => Cuemon.Extensions.Core}/Runtime/Serialization/HierarchySerializer.cs (85%) delete mode 100644 src/Cuemon.Extensions.Text.Json/JsonReaderExtensions.cs diff --git a/src/Cuemon.Core/Extensions/ExceptionDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/ExceptionDecoratorExtensions.cs index 826258520..ab3272825 100644 --- a/src/Cuemon.Core/Extensions/ExceptionDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/ExceptionDecoratorExtensions.cs @@ -28,7 +28,7 @@ public static IEnumerable Flatten(this IDecorator decorato { Validator.ThrowIfNull(decorator); if (decorator.Inner is AggregateException ae) { return ae.Flatten().InnerExceptions; } - return Hierarchy.WhileSourceTraversalHasElements(decorator.Inner, FlattenCallback).Skip(1); + return Decorator.RawEnclose(decorator.Inner).TraverseWhileNotEmpty(FlattenCallback).Skip(1); } private static IEnumerable FlattenCallback(Exception source) @@ -37,4 +37,4 @@ private static IEnumerable FlattenCallback(Exception source) return source.InnerException == null ? Enumerable.Empty() : Arguments.Yield(source.InnerException); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Core/Extensions/ObjectDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/ObjectDecoratorExtensions.cs index 511bc9405..4cc3023f5 100644 --- a/src/Cuemon.Core/Extensions/ObjectDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/ObjectDecoratorExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Reflection; @@ -95,5 +96,48 @@ public static object ChangeType(this IDecorator decorator, Type targetTy } } } + + /// + /// Resolves the default value of a property from the enclosed object of the specified . + /// + /// The to extend. + /// The of the property to resolve the value for. + /// The value of the property if the enclosed object is not null; otherwise, null. + /// This API supports the product infrastructure and is not intended to be used directly from your code. + public static object DefaultPropertyValueResolver(this IDecorator decorator, PropertyInfo pi) + { + var source = decorator?.Inner; + return source == null + ? null + : pi?.GetValue(source, null); + } + + /// + /// Invokes the specified path of the enclosed object of the specified until obstructed by an empty sequence. + /// + /// The to extend. + /// The function delegate that is invoked until the traveled path is obstructed by an empty sequence. + /// An sequence equal to the traveled path of the enclosed object of the specified . + /// + /// -or- is null. + /// + public static IEnumerable TraverseWhileNotEmpty(this IDecorator decorator, Func> traversal) where TSource : class + { + Validator.ThrowIfNull(decorator); + Validator.ThrowIfNull(traversal); + + var source = decorator.Inner; + var stack = new Stack(); + stack.Push(source); + while (stack.Count != 0) + { + var current = stack.Pop(); + foreach (var element in traversal(current)) + { + stack.Push(element); + } + yield return current; + } + } } } diff --git a/src/Cuemon.Core/Extensions/TypeDecoratorExtensions.cs b/src/Cuemon.Core/Extensions/TypeDecoratorExtensions.cs index ea44ac8b8..cf66f76a0 100644 --- a/src/Cuemon.Core/Extensions/TypeDecoratorExtensions.cs +++ b/src/Cuemon.Core/Extensions/TypeDecoratorExtensions.cs @@ -417,7 +417,7 @@ public static bool HasCircularReference(this IDecorator decorator, object Validator.ThrowIfNull(source); Validator.ThrowIfLowerThanOrEqual(maxDepth, 0, nameof(maxDepth)); if (source.GetType() != decorator.Inner) { throw new InvalidOperationException("The specified source has a different type than the underlying type of the extended decorator."); } - valueResolver ??= Infrastructure.DefaultPropertyValueResolver; + valueResolver ??= (s, i) => Decorator.RawEnclose(s).DefaultPropertyValueResolver(i); var hasCircularReference = false; var currentDepth = 0; var stack = new Stack(); diff --git a/src/Cuemon.Core/Infrastructure.cs b/src/Cuemon.Core/Infrastructure.cs deleted file mode 100644 index 0bee963ba..000000000 --- a/src/Cuemon.Core/Infrastructure.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Reflection; - -namespace Cuemon -{ - internal static class Infrastructure - { - internal static object DefaultPropertyValueResolver(object source, PropertyInfo pi) - { - return source == null ? null : pi.GetValue(source, null); - } - } -} diff --git a/src/Cuemon.Core/ObjectPortrayalOptions.cs b/src/Cuemon.Core/ObjectPortrayalOptions.cs index 8958cb5d1..e89800205 100644 --- a/src/Cuemon.Core/ObjectPortrayalOptions.cs +++ b/src/Cuemon.Core/ObjectPortrayalOptions.cs @@ -78,7 +78,7 @@ public ObjectPortrayalOptions() { return string.Format(provider, "{0}={1}", property.Name, Decorator.Enclose(property.PropertyType).ToFriendlyName(o => o.FullName = true)); } - var instanceValue = Infrastructure.DefaultPropertyValueResolver(instance, property); + var instanceValue = Decorator.RawEnclose(instance).DefaultPropertyValueResolver(property); return string.Format(provider, "{0}={1}", property.Name, instanceValue ?? NullValue); } return string.Format(provider, "{0}={1}", property.Name, NoGetterValue); diff --git a/src/Cuemon.Data.SqlClient/SqlDataManager.cs b/src/Cuemon.Data.SqlClient/SqlDataManager.cs index 2a0ca99aa..ebf6d16b0 100644 --- a/src/Cuemon.Data.SqlClient/SqlDataManager.cs +++ b/src/Cuemon.Data.SqlClient/SqlDataManager.cs @@ -224,7 +224,7 @@ private static void HandleSqlDateTime(SqlParameter parameter) private static SqlException ParseException(Exception exception) { - var exceptions = Arguments.Yield(exception).Concat(Decorator.Enclose(exception).Flatten()); + var exceptions = Arguments.Yield(exception).Concat(Decorator.EncloseToExpose(exception).Flatten()); return exceptions.FirstOrDefault(ex => ex is SqlException) as SqlException; } } diff --git a/src/Cuemon.Core/Hierarchy.cs b/src/Cuemon.Extensions.Core/Runtime/Hierarchy.cs similarity index 92% rename from src/Cuemon.Core/Hierarchy.cs rename to src/Cuemon.Extensions.Core/Runtime/Hierarchy.cs index 8d8025b25..728efb04c 100644 --- a/src/Cuemon.Core/Hierarchy.cs +++ b/src/Cuemon.Extensions.Core/Runtime/Hierarchy.cs @@ -3,9 +3,8 @@ using System.Linq; using System.Reflection; using System.Text; -using Cuemon.Reflection; -namespace Cuemon +namespace Cuemon.Extensions.Runtime { /// /// Represents a way to expose a node of a hierarchical structure, including the node object of type . @@ -15,7 +14,6 @@ public sealed class Hierarchy : Wrapper, IHierarchy { private SortedList> _children; - #region Constructors /// /// Initializes a new instance of the class. /// @@ -23,9 +21,7 @@ public Hierarchy() { IsNew = true; } - #endregion - #region Properties private bool IsNew { get; set; } /// @@ -44,13 +40,13 @@ public Hierarchy() /// Gets a value indicating whether this instance has a parent. /// /// true if this instance has a parent; otherwise, false. - public bool HasParent => (Parent != null); + public bool HasParent => Parent != null; /// /// Gets a value indicating whether this instance has any children. /// /// true if this instance has any children; otherwise, false. - public bool HasChildren => (Children.Count > 0); + public bool HasChildren => Children.Count > 0; private SortedList> Children => _children ??= new SortedList>(); @@ -62,9 +58,6 @@ public Hierarchy() /// The node at the specified index. public IHierarchy this[int index] => Decorator.Enclose(this).NodeAt(index); - #endregion - - #region Methods /// /// Allows for the instance on the current node to be replaced with a new . /// @@ -211,7 +204,6 @@ public IHierarchy GetParent() { return Parent; } - #endregion } /// @@ -239,12 +231,12 @@ public static IEnumerable> Find(IHierarchy hierarchy, Func wrapped in an node representing a hierarchical structure. /// /// The source whose properties will be traversed while building the hierarchical structure. - /// The which need to be configured. + /// The which need to be configured. /// An node representing the entirety of a hierarchical structure from the specified . /// /// is null. /// - public static IHierarchy GetObjectHierarchy(object source, Action setup = null) + public static IHierarchy GetObjectHierarchy(object source, Action setup = null) { Validator.ThrowIfNull(source); var options = Patterns.Configure(setup); @@ -320,15 +312,15 @@ public static IHierarchy GetObjectHierarchy(object source, Action /// -or- is null. /// - public static IEnumerable WhileSourceTraversalIsNotNull(TSource source, Func traversal) where TSource : class + public static IEnumerable TraverseWhileNotNull(TSource source, Func traversal) where TSource : class { Validator.ThrowIfNull(source); Validator.ThrowIfNull(traversal); - return WhileSourceTraversalIsNotNullIterator(source, traversal); + return TraverseWhileNotNullIterator(source, traversal); } - private static IEnumerable WhileSourceTraversalIsNotNullIterator(TSource source, Func traversal) where TSource : class + private static IEnumerable TraverseWhileNotNullIterator(TSource source, Func traversal) where TSource : class { var stack = new Stack(); stack.Push(traversal(source)); @@ -351,19 +343,9 @@ private static IEnumerable WhileSourceTraversalIsNotNullIterator /// -or- is null. /// - public static IEnumerable WhileSourceTraversalHasElements(TSource source, Func> traversal) where TSource : class + public static IEnumerable TraverseWhileNotEmpty(TSource source, Func> traversal) where TSource : class { - var stack = new Stack(); - stack.Push(source); - while (stack.Count != 0) - { - var current = stack.Pop(); - foreach (var element in traversal(current)) - { - stack.Push(element); - } - yield return current; - } + return Decorator.EncloseToExpose(source).TraverseWhileNotEmpty(traversal); } internal static IHierarchy AncestorsAndSelf(IHierarchy source) diff --git a/src/Cuemon.Core/Extensions/HierarchyDecoratorExtensions.cs b/src/Cuemon.Extensions.Core/Runtime/HierarchyDecoratorExtensions.cs similarity index 94% rename from src/Cuemon.Core/Extensions/HierarchyDecoratorExtensions.cs rename to src/Cuemon.Extensions.Core/Runtime/HierarchyDecoratorExtensions.cs index 4aff91cb1..18be42f62 100644 --- a/src/Cuemon.Core/Extensions/HierarchyDecoratorExtensions.cs +++ b/src/Cuemon.Extensions.Core/Runtime/HierarchyDecoratorExtensions.cs @@ -6,7 +6,7 @@ using System.Reflection; using Cuemon.Collections.Generic; -namespace Cuemon +namespace Cuemon.Extensions.Runtime { /// /// Extension methods for the interface hidden behind the interface. @@ -69,7 +69,7 @@ public static DateTime UseDateTimeFormatter(this IDecorator public static Guid UseGuidFormatter(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return UseGenericConverter(decorator.Inner); + return decorator.Inner.UseGenericConverter(); } /// @@ -83,7 +83,7 @@ public static Guid UseGuidFormatter(this IDecorator> decora public static string UseStringFormatter(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return UseGenericConverter(decorator.Inner); + return decorator.Inner.UseGenericConverter(); } /// @@ -97,7 +97,7 @@ public static string UseStringFormatter(this IDecorator> de public static decimal UseDecimalFormatter(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return UseGenericConverter(decorator.Inner); + return decorator.Inner.UseGenericConverter(); } /// @@ -155,7 +155,7 @@ public static IDictionary UseDictionary(this IDecorator> de /// An that match the conditions defined by the function delegate , or a default value if no node is found. public static T FindFirstInstance(this IDecorator> decorator, Func, bool> match) { - return FindInstance(decorator, match).FirstOrDefault(); + return decorator.FindInstance(match).FirstOrDefault(); } /// @@ -167,7 +167,7 @@ public static T FindFirstInstance(this IDecorator> decorator, F /// An node that match the conditions defined by the function delegate , or a default value if no node instance is found. public static T FindSingleInstance(this IDecorator> decorator, Func, bool> match) { - return FindInstance(decorator, match).SingleOrDefault(); + return decorator.FindInstance(match).SingleOrDefault(); } /// @@ -179,7 +179,7 @@ public static T FindSingleInstance(this IDecorator> decorator, /// An sequence containing all node instances that match the conditions defined by the specified predicate, if found. public static IEnumerable FindInstance(this IDecorator> decorator, Func, bool> match) { - return Find(decorator, match).Select(h => h.Instance); + return decorator.Find(match).Select(h => h.Instance); } /// @@ -191,7 +191,7 @@ public static IEnumerable FindInstance(this IDecorator> deco /// An node that match the conditions defined by the function delegate , or a default value if no node is found. public static IHierarchy FindFirst(this IDecorator> decorator, Func, bool> match) { - return Find(decorator, match).FirstOrDefault(); + return decorator.Find(match).FirstOrDefault(); } /// @@ -203,7 +203,7 @@ public static IHierarchy FindFirst(this IDecorator> decorato /// An node that match the conditions defined by the function delegate , or a default value if no node is found. public static IHierarchy FindSingle(this IDecorator> decorator, Func, bool> match) { - return Find(decorator, match).SingleOrDefault(); + return decorator.Find(match).SingleOrDefault(); } /// @@ -217,7 +217,7 @@ public static IEnumerable> Find(this IDecorator> { Validator.ThrowIfNull(decorator); Validator.ThrowIfNull(match); - return DescendantsAndSelf(decorator).Where(match); + return decorator.DescendantsAndSelf().Where(match); } /// @@ -245,7 +245,7 @@ public static void ReplaceAll(this IDecorator>> dec Validator.ThrowIfNull(replacer); foreach (var node in decorator.Inner) { - Replace(Decorator.Enclose(node), replacer); + Decorator.Enclose(node).Replace(replacer); } } @@ -261,7 +261,7 @@ public static void ReplaceAll(this IDecorator>> dec public static IHierarchy Root(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return decorator.Inner.HasParent ? AncestorsAndSelf(decorator).FirstOrDefault() : decorator.Inner; + return decorator.Inner.HasParent ? decorator.AncestorsAndSelf().FirstOrDefault() : decorator.Inner; } /// @@ -276,7 +276,7 @@ public static IHierarchy Root(this IDecorator> decorator) public static IEnumerable> AncestorsAndSelf(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - IList> result = new List>(Hierarchy.WhileSourceTraversalIsNotNull(decorator.Inner, Hierarchy.AncestorsAndSelf)); + IList> result = new List>(Hierarchy.TraverseWhileNotNull(decorator.Inner, Hierarchy.AncestorsAndSelf)); return result.Count > 0 ? result.Reverse() : Arguments.Yield(decorator.Inner); } @@ -292,7 +292,7 @@ public static IEnumerable> AncestorsAndSelf(this IDecorator> DescendantsAndSelf(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return Hierarchy.WhileSourceTraversalHasElements(decorator.Inner, Hierarchy.DescendantsAndSelf).Reverse(); + return Hierarchy.TraverseWhileNotEmpty(decorator.Inner, Hierarchy.DescendantsAndSelf).Reverse(); } /// @@ -307,7 +307,7 @@ public static IEnumerable> DescendantsAndSelf(this IDecorator> SiblingsAndSelf(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - return SiblingsAndSelfAt(decorator, decorator.Inner.Depth); + return decorator.SiblingsAndSelfAt(decorator.Inner.Depth); } /// @@ -327,8 +327,8 @@ public static IEnumerable> SiblingsAndSelfAt(this IDecorator NodeAt(this IDecorator> decorator, Validator.ThrowIfNull(decorator); Validator.ThrowIfLowerThan(index, 0, nameof(index)); if (decorator.Inner.Index == index) { return decorator.Inner; } - var allNodes = FlattenAll(decorator); + var allNodes = decorator.FlattenAll(); foreach (var element in allNodes) { if (element.Index == index) { return element; } @@ -373,8 +373,8 @@ public static IHierarchy NodeAt(this IDecorator> decorator, public static IEnumerable> FlattenAll(this IDecorator> decorator) { Validator.ThrowIfNull(decorator); - var root = AncestorsAndSelf(decorator).FirstOrDefault(); - return DescendantsAndSelf(Decorator.Enclose(root)); + var root = decorator.AncestorsAndSelf().FirstOrDefault(); + return Decorator.Enclose(root).DescendantsAndSelf(); } private static T UseGenericConverter(this IHierarchy hierarchy) diff --git a/src/Cuemon.Core/Reflection/ObjectHierarchyOptions.cs b/src/Cuemon.Extensions.Core/Runtime/HierarchyOptions.cs similarity index 94% rename from src/Cuemon.Core/Reflection/ObjectHierarchyOptions.cs rename to src/Cuemon.Extensions.Core/Runtime/HierarchyOptions.cs index 77c05e124..3e256b046 100644 --- a/src/Cuemon.Core/Reflection/ObjectHierarchyOptions.cs +++ b/src/Cuemon.Extensions.Core/Runtime/HierarchyOptions.cs @@ -1,15 +1,16 @@ using System; using System.Reflection; using Cuemon.Configuration; -using Cuemon.Runtime.Serialization; +using Cuemon.Extensions.Runtime.Serialization; +using Cuemon.Reflection; -namespace Cuemon.Reflection +namespace Cuemon.Extensions.Runtime { /// /// Specifies options that is related to and operations. /// /// - public class ObjectHierarchyOptions : IParameterObject + public class HierarchyOptions : IParameterObject { private int _maxDepth; private int _maxCircularCalls; @@ -20,9 +21,9 @@ public class ObjectHierarchyOptions : IParameterObject private MemberReflection _reflectionRules; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ObjectHierarchyOptions() + public HierarchyOptions() { MaxDepth = 10; MaxCircularCalls = 2; @@ -66,7 +67,7 @@ public ObjectHierarchyOptions() property.Name.Equals("TargetSite", StringComparison.Ordinal)); }; HasCircularReference = i => Decorator.Enclose(i.GetType()).HasCircularReference(i); - ValueResolver = Infrastructure.DefaultPropertyValueResolver; + ValueResolver = (s, i) => Decorator.RawEnclose(s).DefaultPropertyValueResolver(i); } /// diff --git a/src/Cuemon.Core/IHierarchy.cs b/src/Cuemon.Extensions.Core/Runtime/IHierarchy.cs similarity index 97% rename from src/Cuemon.Core/IHierarchy.cs rename to src/Cuemon.Extensions.Core/Runtime/IHierarchy.cs index a9b8eb0eb..576b898e6 100644 --- a/src/Cuemon.Core/IHierarchy.cs +++ b/src/Cuemon.Extensions.Core/Runtime/IHierarchy.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Reflection; -namespace Cuemon +namespace Cuemon.Extensions.Runtime { /// /// Provides a generic way to expose a node of a hierarchical structure, including the node object of type . @@ -10,7 +10,6 @@ namespace Cuemon /// The type of the node represented in the hierarchical structure. public interface IHierarchy : IWrapper { - #region Properties /// /// Indicates whether the current node has a parent node. /// @@ -40,9 +39,7 @@ public interface IHierarchy : IWrapper /// /// The node at the specified index. IHierarchy this[int index] { get; } - #endregion - #region Methods /// /// Adds the specified instance to a node in the hierarchical structure representation. /// @@ -88,6 +85,5 @@ public interface IHierarchy : IWrapper /// /// An sequence that represents all the child nodes of the current hierarchical node. IEnumerable> GetChildren(); - #endregion } -} \ No newline at end of file +} diff --git a/src/Cuemon.Core/Runtime/Serialization/HierarchySerializer.cs b/src/Cuemon.Extensions.Core/Runtime/Serialization/HierarchySerializer.cs similarity index 85% rename from src/Cuemon.Core/Runtime/Serialization/HierarchySerializer.cs rename to src/Cuemon.Extensions.Core/Runtime/Serialization/HierarchySerializer.cs index 9189e0472..bed41e2a6 100644 --- a/src/Cuemon.Core/Runtime/Serialization/HierarchySerializer.cs +++ b/src/Cuemon.Extensions.Core/Runtime/Serialization/HierarchySerializer.cs @@ -1,8 +1,7 @@ using System; using System.Text; -using Cuemon.Reflection; -namespace Cuemon.Runtime.Serialization +namespace Cuemon.Extensions.Runtime.Serialization { /// /// Provides a way to serialize objects to nodes of . @@ -13,8 +12,8 @@ public class HierarchySerializer /// Initializes a new instance of the class. /// /// The object to convert to nodes of . - /// The which need to be configured. - public HierarchySerializer(object source, Action setup = null) + /// The which need to be configured. + public HierarchySerializer(object source, Action setup = null) { Nodes = Decorator.Enclose(Hierarchy.GetObjectHierarchy(source, setup)).Root(); } diff --git a/src/Cuemon.Extensions.Text.Json/JsonReaderExtensions.cs b/src/Cuemon.Extensions.Text.Json/JsonReaderExtensions.cs deleted file mode 100644 index f5b4bae91..000000000 --- a/src/Cuemon.Extensions.Text.Json/JsonReaderExtensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Collections.Generic; -using System.Text.Json; -using Cuemon.Text; -using Cuemon.Collections.Generic; - -namespace Cuemon.Extensions.Text.Json -{ - /// - /// Extension methods for the struct. - /// - public static class JsonReaderExtensions - { - private const string PropertyNameKey = "reader.Value"; - - /// - /// Converts the JSON hierarchy of an into an . - /// - /// The reader to convert. - /// An implementation that uses . - public static IHierarchy ToHierarchy(this Utf8JsonReader reader) - { - var index = 0; - var depthIndexes = new Dictionary>(); - var dimension = 0; - IHierarchy hierarchy = new Hierarchy(); - var array = new List(); - hierarchy.Add(new DataPair("root", null, typeof(string))); - while (reader.Read()) - { - object typeStrongValue; - switch (reader.TokenType) - { - case JsonTokenType.StartArray: - if (reader.TokenType == JsonTokenType.EndArray) { goto case JsonTokenType.EndArray; } - if (reader.TokenType != JsonTokenType.StartArray && reader.TokenType != JsonTokenType.StartObject && reader.TokenType != JsonTokenType.EndObject) - { - typeStrongValue = ParserFactory.FromValueType().Parse(reader.GetString()); - array.Add(new DataPair(hierarchy[index].Data[PropertyNameKey]?.ToString(), typeStrongValue, typeStrongValue.GetType())); - } - while (reader.Read()) { goto case JsonTokenType.StartArray; } - break; - case JsonTokenType.PropertyName: - hierarchy[Decorator.Enclose(depthIndexes).GetDepthIndex(reader.CurrentDepth, index, dimension)].Add(new DataPair(reader.GetString(), null, typeof(string))).Data.Add(PropertyNameKey, reader.GetString()); - index++; - break; - case JsonTokenType.EndArray: - var indexCopy = index; - foreach (var item in array) - { - hierarchy[indexCopy].Add(item); - index++; - } - array.Clear(); - break; - case JsonTokenType.EndObject: - if (reader.CurrentDepth == 1) { dimension++; } - break; - case JsonTokenType.Number: - case JsonTokenType.String: - case JsonTokenType.True: - case JsonTokenType.False: - case JsonTokenType.Null: - typeStrongValue = ParserFactory.FromValueType().Parse(reader.GetString()); - hierarchy[index].Replace(new DataPair(hierarchy[index].Data[PropertyNameKey]?.ToString(), typeStrongValue, typeStrongValue.GetType())); - hierarchy[index].Data.Remove(PropertyNameKey); - break; - } - } - return hierarchy; - } - } -} diff --git a/src/Cuemon.Extensions.Xml/HierarchyExtensions.cs b/src/Cuemon.Extensions.Xml/HierarchyExtensions.cs index e07cdedca..eba9edd48 100644 --- a/src/Cuemon.Extensions.Xml/HierarchyExtensions.cs +++ b/src/Cuemon.Extensions.Xml/HierarchyExtensions.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Xml.Serialization; +using Cuemon.Extensions.Runtime; using Cuemon.Xml; using Cuemon.Xml.Serialization; @@ -74,4 +75,4 @@ public static IEnumerable> OrderByXmlAttributes(this IEnumerabl return Decorator.Enclose(hierarchies).OrderByXmlAttributes(); } } -} \ No newline at end of file +} diff --git a/src/Cuemon.Extensions.Xml/XmlReaderExtensions.cs b/src/Cuemon.Extensions.Xml/XmlReaderExtensions.cs index f1253c6a7..5de92055b 100644 --- a/src/Cuemon.Extensions.Xml/XmlReaderExtensions.cs +++ b/src/Cuemon.Extensions.Xml/XmlReaderExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Xml; +using Cuemon.Extensions.Runtime; using Cuemon.Xml; namespace Cuemon.Extensions.Xml diff --git a/src/Cuemon.Xml/Cuemon.Xml.csproj b/src/Cuemon.Xml/Cuemon.Xml.csproj index 58b6ca218..02f7aa648 100644 --- a/src/Cuemon.Xml/Cuemon.Xml.csproj +++ b/src/Cuemon.Xml/Cuemon.Xml.csproj @@ -11,7 +11,8 @@ + - \ No newline at end of file + diff --git a/src/Cuemon.Xml/Extensions/HierarchyDecoratorExtensions.cs b/src/Cuemon.Xml/Extensions/HierarchyDecoratorExtensions.cs index 0ea6d868c..8c48a1345 100644 --- a/src/Cuemon.Xml/Extensions/HierarchyDecoratorExtensions.cs +++ b/src/Cuemon.Xml/Extensions/HierarchyDecoratorExtensions.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Xml.Serialization; +using Cuemon.Extensions.Runtime; using Cuemon.Reflection; using Cuemon.Xml.Serialization; diff --git a/src/Cuemon.Xml/Extensions/Serialization/Converters/XmlConverterDecoratorExtensions.cs b/src/Cuemon.Xml/Extensions/Serialization/Converters/XmlConverterDecoratorExtensions.cs index 85b4b2287..4310b99b1 100644 --- a/src/Cuemon.Xml/Extensions/Serialization/Converters/XmlConverterDecoratorExtensions.cs +++ b/src/Cuemon.Xml/Extensions/Serialization/Converters/XmlConverterDecoratorExtensions.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Xml; using Cuemon.Diagnostics; +using Cuemon.Extensions.Runtime; using Cuemon.Xml.Linq; namespace Cuemon.Xml.Serialization.Converters diff --git a/src/Cuemon.Xml/Extensions/XmlReaderDecoratorExtensions.cs b/src/Cuemon.Xml/Extensions/XmlReaderDecoratorExtensions.cs index 351a61ad2..0273ee419 100644 --- a/src/Cuemon.Xml/Extensions/XmlReaderDecoratorExtensions.cs +++ b/src/Cuemon.Xml/Extensions/XmlReaderDecoratorExtensions.cs @@ -5,6 +5,7 @@ using System.Xml.XPath; using Cuemon.Text; using Cuemon.Collections.Generic; +using Cuemon.Extensions.Runtime; using Cuemon.Xml.Serialization; namespace Cuemon.Xml diff --git a/src/Cuemon.Xml/Extensions/XmlWriterDecoratorExtensions.cs b/src/Cuemon.Xml/Extensions/XmlWriterDecoratorExtensions.cs index 2e9c13eab..711588a4c 100644 --- a/src/Cuemon.Xml/Extensions/XmlWriterDecoratorExtensions.cs +++ b/src/Cuemon.Xml/Extensions/XmlWriterDecoratorExtensions.cs @@ -2,7 +2,8 @@ using System.Reflection; using System.Xml; using Cuemon.Collections.Generic; -using Cuemon.Runtime.Serialization; +using Cuemon.Extensions.Runtime; +using Cuemon.Extensions.Runtime.Serialization; using Cuemon.Xml.Serialization; using Cuemon.Xml.Serialization.Formatters; diff --git a/src/Cuemon.Xml/Serialization/Converters/DefaultXmlConverter.cs b/src/Cuemon.Xml/Serialization/Converters/DefaultXmlConverter.cs index cbc4ef64e..bc9e3f7fa 100644 --- a/src/Cuemon.Xml/Serialization/Converters/DefaultXmlConverter.cs +++ b/src/Cuemon.Xml/Serialization/Converters/DefaultXmlConverter.cs @@ -8,6 +8,8 @@ using System.Xml; using System.Xml.Serialization; using Cuemon.Collections.Generic; +using Cuemon.Extensions; +using Cuemon.Extensions.Runtime; using Cuemon.Reflection; using Cuemon.Xml.Linq; diff --git a/test/Cuemon.Core.Tests/Runtime/Serialization/HierarchySerializerTest.cs b/test/Cuemon.Core.Tests/Runtime/Serialization/HierarchySerializerTest.cs index ff91bdcef..c93eb29b9 100644 --- a/test/Cuemon.Core.Tests/Runtime/Serialization/HierarchySerializerTest.cs +++ b/test/Cuemon.Core.Tests/Runtime/Serialization/HierarchySerializerTest.cs @@ -1,5 +1,6 @@ using Cuemon.Assets; using Codebelt.Extensions.Xunit; +using Cuemon.Extensions.Runtime.Serialization; using Xunit; using Xunit.Abstractions; diff --git a/test/Cuemon.Extensions.Xml.Tests/XmlReaderExtensionsTest.cs b/test/Cuemon.Extensions.Xml.Tests/XmlReaderExtensionsTest.cs index 722e71be4..6b163e1f2 100644 --- a/test/Cuemon.Extensions.Xml.Tests/XmlReaderExtensionsTest.cs +++ b/test/Cuemon.Extensions.Xml.Tests/XmlReaderExtensionsTest.cs @@ -4,7 +4,7 @@ using Cuemon.Extensions.IO; using Cuemon.Extensions.Xml.Assets; using Codebelt.Extensions.Xunit; -using Cuemon.Runtime.Serialization; +using Cuemon.Extensions.Runtime.Serialization; using Cuemon.Xml.Serialization.Formatters; using Xunit; using Xunit.Abstractions; @@ -112,6 +112,7 @@ public void ToHierarchy_ShouldConvertReaderToHierarchy() var sut4 = sut3.ToHierarchy(); var sut5 = sut4.GetChildren(); // namespace + TestOutput.WriteLine(sut1.ToString()); TestOutput.WriteLine(sut2.ToEncodedString()); Assert.NotNull(sut3); From c31c9ca315d776b527f24d040341bb7b8ab17490 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 15:38:25 +0100 Subject: [PATCH 08/11] :rotating_light: justified a few codesmells --- src/Cuemon.Core/GlobalSuppressions.cs | 3 --- src/Cuemon.Extensions.Core/GlobalSuppressions.cs | 1 + src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs | 2 -- src/Cuemon.Xml/GlobalSuppressions.cs | 6 ++++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Cuemon.Core/GlobalSuppressions.cs b/src/Cuemon.Core/GlobalSuppressions.cs index 8a975064f..567bf7a51 100644 --- a/src/Cuemon.Core/GlobalSuppressions.cs +++ b/src/Cuemon.Core/GlobalSuppressions.cs @@ -33,14 +33,12 @@ [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``5(``0,``1,``2,``3,System.Action{Cuemon.Reflection.ActivatorOptions})~``4")] [assembly: SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "By design; allow up till 5 arguments (more under certain conditions).", Scope = "member", Target = "~M:Cuemon.Reflection.ActivatorFactory.CreateInstance``6(``0,``1,``2,``3,``4,System.Action{Cuemon.Reflection.ActivatorOptions})~``5")] [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "By design; although a good rule, this is the exception to the rule.", Scope = "member", Target = "~M:Cuemon.Calculator.CalculateCore``1(``0,``0,Cuemon.AssignmentOperator)~``0")] -[assembly: SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "Out of scope.", Scope = "type", Target = "~T:Cuemon.Collections.DataPairDictionary")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~F:Cuemon.Reflection.MemberReflection.Everything")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Reflection.MemberReflection.#ctor(System.Action{Cuemon.Reflection.MemberReflectionOptions})")] [assembly: SuppressMessage("Major Code Smell", "S3011:Reflection should not be used to increase accessibility of classes, methods, or fields", Justification = "By design.", Scope = "member", Target = "~M:Cuemon.Globalization.ResourceAttribute.GetString(System.String)~System.String")] [assembly: SuppressMessage("Major Code Smell", "S1854:Unused assignments should be removed", Justification = "False Positive", Scope = "member", Target = "~M:Cuemon.DateSpan.#ctor(System.DateTime,System.DateTime,System.Globalization.Calendar)")] [assembly: SuppressMessage("Style", "IDE0220:Add explicit cast", Justification = "False-Positive", Scope = "member", Target = "~M:Cuemon.StringReplaceEngine.RenderReplacement~System.String")] [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "Prioritize functionality and correctness over complexity metrics.", Scope = "member", Target = "~M:Cuemon.DateSpan.#ctor(System.DateTime,System.DateTime,System.Globalization.Calendar)")] -[assembly: SuppressMessage("Major Code Smell", "S2589:Boolean expressions should not be gratuitous", Justification = "False Positive", Scope = "member", Target = "~M:Cuemon.Hierarchy.WhileSourceTraversalIsNotNullIterator``1(``0,System.Func{``0,``0})~System.Collections.Generic.IEnumerable{``0}")] [assembly: SuppressMessage("Major Code Smell", "S2589:Boolean expressions should not be gratuitous", Justification = "False Positive", Scope = "member", Target = "~M:Cuemon.Security.CyclicRedundancyCheck.PolynomialTableInitializerCore(System.UInt64)~System.Collections.Generic.List{System.UInt64}")] [assembly: SuppressMessage("Minor Code Smell", "S3236:Caller information arguments should not be provided explicitly", Justification = "By design - and unit tested to that no information is lost.", Scope = "member", Target = "~M:Cuemon.Decorator`1.#ctor(`0,System.Boolean,System.String)")] [assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "Acceptable.", Scope = "member", Target = "~M:Cuemon.Text.ParserFactory.FromValueType~Cuemon.Text.IConfigurableParser{System.Object,Cuemon.FormattingOptions}")] @@ -68,7 +66,6 @@ [assembly: SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "By design; supports consistent developer experience for all formatters, e.g., SerializeObject/DeserializeObject.", Scope = "member", Target = "~M:Cuemon.Runtime.Serialization.Formatters.StreamFormatter`1.SerializeObject(System.Object,System.Type,`0)~System.IO.Stream")] [assembly: SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "By design; supports consistent developer experience for all formatters, e.g., SerializeObject/DeserializeObject.", Scope = "member", Target = "~M:Cuemon.Runtime.Serialization.Formatters.StreamFormatter`1.SerializeObject(System.Object,System.Type,System.Action{`0})~System.IO.Stream")] [assembly: SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "False-Positive. Overload exists.", Scope = "member", Target = "~M:Cuemon.DateSpan.Parse(System.String)~Cuemon.DateSpan")] -[assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "Not relevant in this context.", Scope = "member", Target = "~M:Cuemon.Runtime.Serialization.HierarchySerializer.ToString(System.Text.StringBuilder,Cuemon.IHierarchy{System.Object})")] [assembly: SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "Intentionally written for only en-US support.", Scope = "member", Target = "~M:Cuemon.Reflection.MemberArgumentDecoratorExtensions.CreateException(Cuemon.IDecorator{System.Collections.Generic.Stack{System.Collections.Generic.IList{Cuemon.Reflection.MemberArgument}}},System.Boolean)~System.Exception")] [assembly: SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = "Explicit implementation.", Scope = "type", Target = "~T:Cuemon.Diagnostics.Failure")] [assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Byteordermark - best effort.", Scope = "member", Target = "~M:Cuemon.Text.ByteOrderMark.TryDetectEncoding(System.IO.Stream,System.Text.Encoding@)~System.Boolean")] diff --git a/src/Cuemon.Extensions.Core/GlobalSuppressions.cs b/src/Cuemon.Extensions.Core/GlobalSuppressions.cs index d19e48ecf..dcce8d859 100644 --- a/src/Cuemon.Extensions.Core/GlobalSuppressions.cs +++ b/src/Cuemon.Extensions.Core/GlobalSuppressions.cs @@ -105,3 +105,4 @@ [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow to exceed generic arguments recommendation.", Scope = "member", Target = "~M:Cuemon.Extensions.TesterFuncFactory.Create``16(Cuemon.TesterFunc{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,``15},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13)~Cuemon.TesterFuncFactory{Cuemon.MutableTuple{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13},``14,``15}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow to exceed generic arguments recommendation.", Scope = "member", Target = "~M:Cuemon.Extensions.TesterFuncFactory.Create``17(Cuemon.TesterFunc{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14,``15,``16},``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14)~Cuemon.TesterFuncFactory{Cuemon.MutableTuple{``0,``1,``2,``3,``4,``5,``6,``7,``8,``9,``10,``11,``12,``13,``14},``15,``16}")] [assembly: SuppressMessage("Major Code Smell", "S107:Methods should not have too many parameters", Justification = "By design; allow to exceed generic arguments recommendation.", Scope = "member", Target = "~M:Cuemon.Extensions.TesterFuncFactory.Create``9(Cuemon.TesterFunc{``0,``1,``2,``3,``4,``5,``6,``7,``8},``0,``1,``2,``3,``4,``5,``6)~Cuemon.TesterFuncFactory{Cuemon.MutableTuple{``0,``1,``2,``3,``4,``5,``6},``7,``8}")] +[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "TODO - due to .NET 9 release this week, its kept as-is with this round of refactoring.", Scope = "member", Target = "~M:Cuemon.Extensions.Runtime.Hierarchy.GetObjectHierarchy(System.Object,System.Action{Cuemon.Extensions.Runtime.HierarchyOptions})~Cuemon.Extensions.Runtime.IHierarchy{System.Object}")] diff --git a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs index cbabe6827..5d5c3bb5b 100644 --- a/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs +++ b/src/Cuemon.Extensions.Text.Json/GlobalSuppressions.cs @@ -5,6 +5,4 @@ using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] -[assembly: SuppressMessage("Major Code Smell", "S907:\"goto\" statement should not be used", Justification = "Transitioned legacy code ;-)", Scope = "member", Target = "~M:Cuemon.Extensions.Text.Json.JsonReaderExtensions.ToHierarchy(System.Text.Json.Utf8JsonReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] [assembly: SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "False-positive; .NET 7 reads this value.", Scope = "member", Target = "~P:Cuemon.Extensions.Text.Json.Converters.FlagsEnumConverter.TypeToConvert")] diff --git a/src/Cuemon.Xml/GlobalSuppressions.cs b/src/Cuemon.Xml/GlobalSuppressions.cs index 1e1230d11..f02a27557 100644 --- a/src/Cuemon.Xml/GlobalSuppressions.cs +++ b/src/Cuemon.Xml/GlobalSuppressions.cs @@ -7,8 +7,6 @@ [assembly: SuppressMessage("Major Code Smell", "S907:\"goto\" statement should not be used", Justification = "Legacy implementation.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.DefaultXmlConverter.ParseReadXmlDefault(System.Xml.XmlReader,System.Type)~System.Object")] [assembly: SuppressMessage("Minor Code Smell", "S3626:Jump statements should not be redundant", Justification = "False-positive.", Scope = "member", Target = "~M:Cuemon.Xml.XmlStreamFactory.CreateStream(System.Action{System.Xml.XmlWriter},System.Action{System.Xml.XmlWriterSettings})~System.IO.Stream")] -[assembly: SuppressMessage("Major Code Smell", "S907:\"goto\" statement should not be used", Justification = "Legacy implementation.", Scope = "member", Target = "~M:Cuemon.Xml.XmlReaderDecoratorExtensions.BuildHierarchy(System.Xml.XmlReader)~Cuemon.IHierarchy{Cuemon.DataPair}")] -[assembly: SuppressMessage("Major Code Smell", "S1066:Collapsible \"if\" statements should be merged", Justification = "Readability; at least for me.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.DefaultXmlConverter.SkipIfNullOrEmptyEnumerable(Cuemon.IHierarchy{System.Object})~System.Boolean")] [assembly: SuppressMessage("Critical Bug", "S4275:Getters and setters should access the expected fields", Justification = "By design; to provide XmlIgnoreAttribute.", Scope = "member", Target = "~P:Cuemon.Xml.Serialization.XmlWrapper.InstanceType")] [assembly: SuppressMessage("Critical Bug", "S4275:Getters and setters should access the expected fields", Justification = "By design; to provide XmlIgnoreAttribute.", Scope = "member", Target = "~P:Cuemon.Xml.Serialization.XmlWrapper.MemberReference")] [assembly: SuppressMessage("Style", "IDE0130:Namespace does not match folder structure", Justification = "Intentional as these embark on IDecorator.", Scope = "namespace", Target = "~N:Cuemon.Xml")] @@ -18,3 +16,7 @@ [assembly: SuppressMessage("Security", "CA5372:Use XmlReader for XPathDocument constructor", Justification = "Convenience.", Scope = "member", Target = "~M:Cuemon.Xml.XPath.XPathDocumentFactory.CreateDocument(System.Uri)~System.Xml.XPath.XPathDocument")] [assembly: SuppressMessage("Security", "CA5372:Use XmlReader for XPathDocument constructor", Justification = "Convenience.", Scope = "member", Target = "~M:Cuemon.Xml.XPath.XPathDocumentFactory.CreateDocument(System.IO.Stream,System.Boolean)~System.Xml.XPath.XPathDocument")] [assembly: SuppressMessage("Major Code Smell", "S1172:Unused method parameters should be removed", Justification = "False-positive; value is conditionally used.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.ExceptionConverter.ParseXmlReader(System.Xml.XmlReader,System.Type)~System.Collections.Generic.Stack{System.Collections.Generic.IList{Cuemon.Reflection.MemberArgument}}")] +[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "TODO - due to .NET 9 release this week, its kept as-is with this round of refactoring.", Scope = "member", Target = "~M:Cuemon.Xml.XmlReaderDecoratorExtensions.BuildHierarchy(System.Xml.XmlReader)~Cuemon.Extensions.Runtime.IHierarchy{Cuemon.DataPair}")] +[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "TODO - due to .NET 9 release this week, its kept as-is with this round of refactoring.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.XmlConverterDecoratorExtensions.AddEnumerableConverter(Cuemon.IDecorator{System.Collections.Generic.IList{Cuemon.Xml.Serialization.Converters.XmlConverter}})~Cuemon.IDecorator{System.Collections.Generic.IList{Cuemon.Xml.Serialization.Converters.XmlConverter}}")] +[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "TODO - due to .NET 9 release this week, its kept as-is with this round of refactoring.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.DefaultXmlConverter.ParseReadXmlDefault(System.Xml.XmlReader,System.Type)~System.Object")] +[assembly: SuppressMessage("Critical Code Smell", "S3776:Cognitive Complexity of methods should not be too high", Justification = "TODO - due to .NET 9 release this week, its kept as-is with this round of refactoring.", Scope = "member", Target = "~M:Cuemon.Xml.Serialization.Converters.ExceptionConverter.ParseXmlReader(System.Xml.XmlReader,System.Type)~System.Collections.Generic.Stack{System.Collections.Generic.IList{Cuemon.Reflection.MemberArgument}}")] From 95bfed2a45b3b63cc8ef86c21192f39941457904 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 15:38:47 +0100 Subject: [PATCH 09/11] :white_check_mark: updated test due to slimming for core assembly --- .../Reflection/AssemblyDecoratorExtensionsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs b/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs index 269720070..a86b4d515 100644 --- a/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs +++ b/test/Cuemon.Core.Tests/Reflection/AssemblyDecoratorExtensionsTest.cs @@ -41,7 +41,7 @@ public void GetTypes_ShouldReturnAllTypesFromCuemonCore() TestOutput.WriteLine(disposableTypes.ToDelimitedString()); - Assert.InRange(allTypesCount, 375, 425); // range because of tooling on CI adding dynamic types and high range of refactoring + Assert.InRange(allTypesCount, 325, 375); // range because of tooling on CI adding dynamic types and high range of refactoring Assert.Equal(5, disposableTypesCount); Assert.Equal(4, configurationTypesCount); } From 50733453e11ce9f6c773580e6cb7261bf14b3b99 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 20:04:58 +0100 Subject: [PATCH 10/11] :package: updated NuGet package definition --- .nuget/Cuemon.Core/PackageReleaseNotes.txt | 15 +++++++++++++++ .../PackageReleaseNotes.txt | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/.nuget/Cuemon.Core/PackageReleaseNotes.txt b/.nuget/Cuemon.Core/PackageReleaseNotes.txt index 9cf7a4f38..31b091347 100644 --- a/.nuget/Cuemon.Core/PackageReleaseNotes.txt +++ b/.nuget/Cuemon.Core/PackageReleaseNotes.txt @@ -45,6 +45,21 @@ Availability: .NET 9, .NET 8 and .NET Standard 2.0 - REMOVED UnitPrefix enum from the Cuemon namespace - REMOVED UnitPrefixFormatter class from the Cuemon namespace - REMOVED ZeroPrefix class from the Cuemon namespace +- REMOVED DataPairCollection class from the Cuemon.Collections namespace +- REMOVED DataPairDictionary class from the Cuemon.Collections namespace +- REMOVED Initializer class from the Cuemon namespace +- REMOVED InitializerBuilder class from the Cuemon namespace +- REMOVED Mapping class from the Cuemon namespace +- REMOVED IndexMapping class from the Cuemon namespace +- REMOVED HorizontalDirection enum from the Cuemon namespace +- REMOVED VerticalDirection enum from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- REMOVED IWrapper interface from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- REMOVED Wrapper class from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- REMOVED HierarchyDecoratorExtensions class from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- REMOVED Hierarchy class from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- REMOVED IHierarchy interface from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- REMOVED ObjectHierarchyOptions class from the Cuemon.Reflection namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly and renamed to HierarchyOptions) +- REMOVED HierarchySerializer class from the Cuemon.Runtime.Serialization namespace (moved to the Cuemon.Extensions.Runtime.Serialization namespace in the Cuemon.Extensions.Core assembly)   # New Features - ADDED Failure record in the Cuemon.Diagnostics namespace that represents a failure model with detailed information about an exception diff --git a/.nuget/Cuemon.Extensions.Core/PackageReleaseNotes.txt b/.nuget/Cuemon.Extensions.Core/PackageReleaseNotes.txt index 6db089461..c293c891d 100644 --- a/.nuget/Cuemon.Extensions.Core/PackageReleaseNotes.txt +++ b/.nuget/Cuemon.Extensions.Core/PackageReleaseNotes.txt @@ -9,6 +9,7 @@ Availability: .NET 9, .NET 8 and .NET Standard 2.0 - REMOVED ConditionExtensions class from the Cuemon.Extensions namespace and moved members to Condition class in the Cuemon.Core assembly (Cuemon namespace) - REMOVED ValidatorExtensions class from the Cuemon.Extensions namespace and moved members to Validator class in the Cuemon.Core assembly (Cuemon namespace) - REMOVED ReplaceLineEndings extension method from the StringExtensions class in the Cuemon.Extensions namespace +- REMOVED MappingExtensions class from the Cuemon.Extensions namespace   # New Features - ADDED ActionFactory class in the Cuemon.Extensions namespace that provides access to factory methods for creating ActionFactory{TTuple} objects that encapsulate a delegate with a variable amount of generic arguments @@ -16,6 +17,14 @@ Availability: .NET 9, .NET 8 and .NET Standard 2.0 - ADDED MutableTupleFactory class in the Cuemon.Extensions namespace that provides access to factory methods for creating MutableTuple objects - ADDED TesterFuncFactory class in the Cuemon.Extensions namespace that provides access to factory methods for creating TesterFuncFactory{TTuple, TResult, TSuccess} objects that encapsulate a tester function delegate with a variable amount of generic arguments - ADDED AsyncDisposable class in the Cuemon.Extensions namespace that provides a mechanism for asynchronously releasing both managed and unmanaged resources with focus on the former +- ADDED VerticalDirection enum in the Cuemon.Extensions namespace that specifies a set of values defining a vertical direction +- ADDED IWrapper interface in the Cuemon.Extensions namespace that defines a generic way to wrap an object instance inside another object +- ADDED Wrapper class in the Cuemon.Extensions namespace that provides a way to wrap an object instance inside another object +- ADDED Hierarchy class in the Cuemon.Extensions.Runtime namespace that represents a way to expose a node of a hierarchical structure, including the node object type +- ADDED HierarchyDecoratorExtensions class in the Cuemon.Extensions.Runtime namespace that provides (hidden) extensions to the IHierarchy interface +- ADDED HierarchyOptions class in the Cuemon.Extensions.Runtime namespace that represents a set of options to configure the behavior of the Hierarchy and HierarchySerializer class +- ADDED IHierarchy interface in the Cuemon.Extensions.Runtime namespace that defines a way to expose a node of a hierarchical structure +- ADDED HierarchySerializer class in the Cuemon.Extensions.Runtime.Serialization namespace that provides a way to serialize objects to nodes of IHierarchy   Version 8.3.2 Availability: .NET 8, .NET 6 and .NET Standard 2.0 From 291a4b57b84f8e51b1af853c47c167a0df77f007 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Mon, 11 Nov 2024 20:05:07 +0100 Subject: [PATCH 11/11] :speech_balloon: updated community health pages --- CHANGELOG.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eabb946a6..8e5f05b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), For more details, please refer to `PackageReleaseNotes.txt` on a per assembly basis in the `.nuget` folder. -## [9.0.0] - TBD (sometime in November 2024) +## [9.0.0] - 2024-11-13 > [!IMPORTANT] > The following projects has been removed with this release and migrated to [Codebelt](https://github.com/codebeltnet): @@ -21,6 +21,8 @@ For more details, please refer to `PackageReleaseNotes.txt` on a per assembly ba > [!NOTE] > Types that are removed from this solution (but otherwise fits naturally together) will be migrated to smaller and more focused repositories in the [Codebelt](https://github.com/codebeltnet) organization, renamed to better reflect their purpose and published as standalone packages on NuGet. +> +> - [Codebelt.Unitify](https://github.com/codebeltnet/unitify) is an example of a repository that received types from this solution and is now a standalone library that provides a uniform way of working with prefixes and multiples in the context of units of measure. This major release is first and foremost focused on ironing out any wrinkles that have been introduced with .NET 9 preview releases so the final release is production ready together with the official launch from Microsoft. @@ -32,6 +34,9 @@ Highlighted features included in this release: - Support for both **FaultDetails** (HttpExceptionDescriptor) and **ProblemDetails** in the context of ASP.NET (both vanilla and MVC) - Reduced footprint in the core assemblies by removing obsolete and redundant code + - Went from approximately 700 KB to 500 KB in the core assembly + - Types reduced with approximately 20% which is about 100 types +- Central Package Management (CPM) for all projects in the solution ### Added @@ -54,6 +59,14 @@ Highlighted features included in this release: - MutableTupleFactory class in the Cuemon.Extensions namespace that provides access to factory methods for creating MutableTuple objects - TesterFuncFactory class in the Cuemon.Extensions namespace that provides access to factory methods for creating TesterFuncFactory{TTuple, TResult, TSuccess} objects that encapsulate a tester function delegate with a variable amount of generic arguments - AsyncDisposable class in the Cuemon.Extensions namespace that provides a mechanism for asynchronously releasing both managed and unmanaged resources with focus on the former +- VerticalDirection enum in the Cuemon.Extensions namespace that specifies a set of values defining a vertical direction +- IWrapper interface in the Cuemon.Extensions namespace that defines a generic way to wrap an object instance inside another object +- Wrapper class in the Cuemon.Extensions namespace that provides a way to wrap an object instance inside another object +- Hierarchy class in the Cuemon.Extensions.Runtime namespace that represents a way to expose a node of a hierarchical structure, including the node object type +- HierarchyDecoratorExtensions class in the Cuemon.Extensions.Runtime namespace that provides (hidden) extensions to the IHierarchy interface +- HierarchyOptions class in the Cuemon.Extensions.Runtime namespace that represents a set of options to configure the behavior of the Hierarchy and HierarchySerializer class +- IHierarchy interface in the Cuemon.Extensions.Runtime namespace that defines a way to expose a node of a hierarchical structure +- HierarchySerializer class in the Cuemon.Extensions.Runtime.Serialization namespace that provides a way to serialize objects to nodes of IHierarchy ### Changed @@ -165,6 +178,21 @@ Highlighted features included in this release: - UnitPrefix enum from the Cuemon namespace (breaking change) - UnitPrefixFormatter class from the Cuemon namespace (breaking change) - ZeroPrefix class from the Cuemon namespace (breaking change) +- DataPairCollection class from the Cuemon.Collections namespace +- DataPairDictionary class from the Cuemon.Collections namespace +- Initializer class from the Cuemon namespace +- InitializerBuilder class from the Cuemon namespace +- Mapping class from the Cuemon namespace +- IndexMapping class from the Cuemon namespace +- HorizontalDirection enum from the Cuemon namespace +- VerticalDirection enum from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- IWrapper interface from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- Wrapper class from the Cuemon namespace (moved to the Cuemon.Extensions namespace in the Cuemon.Extensions.Core assembly) +- HierarchyDecoratorExtensions class from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- Hierarchy class from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- IHierarchy interface from the Cuemon namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly) +- ObjectHierarchyOptions class from the Cuemon.Reflection namespace (moved to the Cuemon.Extensions.Runtime namespace in the Cuemon.Extensions.Core assembly and renamed to HierarchyOptions) +- HierarchySerializer class from the Cuemon.Runtime.Serialization namespace (moved to the Cuemon.Extensions.Runtime.Serialization namespace in the Cuemon.Extensions.Core assembly) ## [8.3.2] - 2024-08-04