From 3a2cf106f449c44dd4853b47081ae0165a7f86d8 Mon Sep 17 00:00:00 2001 From: samatstarion Date: Thu, 5 Nov 2026 17:49:39 +0100 Subject: [PATCH 1/2] [Update] dependencies and refactor helpers to make the used ones explicit --- Directory.Packages.props | 97 +++++++++---------- .../ClassHelperTestFixture.cs | 4 +- .../PropertyHelperTestFixture.cs | 2 +- .../HandleBarHelpers/ClassHelper.cs | 2 +- .../HandleBarHelpers/PropertyHelper.cs | 6 +- .../Utilities/StreamExtensionsTestFixture.cs | 6 +- 6 files changed, 54 insertions(+), 63 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 8d1e23149..c4ddc91ed 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,13 +1,10 @@ - - - - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs index ee395080f..5eea88b02 100644 --- a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs +++ b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs @@ -138,7 +138,7 @@ public void Verify_that_WriteCountAllNonDerivedProperties_writes_numeric_count() [Test] public void Verify_that_QueryAllNonDerivedNonRedefinedProperties_does_not_throw() { - var testClass = this.allClasses.First(c => !c.IsAbstract && c.QueryAllNonDerivedNonRedefinedProperties().Count > 0); + var testClass = this.allClasses.First(c => !c.IsAbstract && CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(c).Count > 0); Assert.That(() => this.RenderWithClassContext( "{{#Class.QueryAllNonDerivedNonRedefinedProperties}}item{{/Class.QueryAllNonDerivedNonRedefinedProperties}}", @@ -150,7 +150,7 @@ public void Verify_that_QueryAllNonDerivedNonRedefinedProperties_returns_expecte { var testClass = this.allClasses.First(c => !c.IsAbstract); - var expectedCount = testClass.QueryAllNonDerivedNonRedefinedProperties().Count; + var expectedCount = CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(testClass).Count; var countResult = this.RenderWithClassContext("{{Class.WriteCountAllNonDerivedNonRedefinedProperties}}", testClass); var actualCount = int.Parse(countResult.Trim()); diff --git a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs index ecdc7a98b..64ac2d211 100644 --- a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs +++ b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs @@ -148,7 +148,7 @@ public void Verify_that_WriteForDTOClass_generates_property_for_each_class() { foreach (var @class in this.allClasses.Where(c => !c.IsAbstract).Take(5)) { - var properties = @class.QueryAllNonDerivedNonRedefinedProperties(); + var properties = CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(@class); foreach (var property in properties.Take(3)) { diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs index c17890632..881ad0ca6 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs @@ -168,7 +168,7 @@ public static void RegisterClassHelper(this IHandlebars handlebars) throw new ArgumentException("#Class.QueryAllNonDerivedNonRedefinedProperties: supposed to be IClass"); } - return @class.QueryAllNonDerivedNonRedefinedProperties(); + return Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(@class); }); // writes the count of non-derived and non Redefined properties of the IClass diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs index 3adf362cd..f9c7ce368 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs @@ -247,7 +247,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) if (!isRedefinedPropertyInContext) { - if (property.QueryIsEnumPropertyWithDefaultValue()) + if (PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property)) { sb.Append($" = {property.Type.Name.CapitalizeFirstLetter()}.{property.QueryDefaultValueAsString().CapitalizeFirstLetter()};"); } @@ -475,7 +475,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) if ((!property.IsDerived || property.IsDerivedUnion) && !isRedefinedPropertyInContext) { - if (property.QueryIsEnumPropertyWithDefaultValue()) + if (PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property)) { sb.Append($" = {property.Type.Name.CapitalizeFirstLetter()}.{property.QueryDefaultValueAsString().CapitalizeFirstLetter()};"); } @@ -1052,7 +1052,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) } return property.QueryIsEnum() - ? property.QueryIsEnumPropertyWithDefaultValue() + ? PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property) : (property.QueryHasDefaultValue() && property.QueryIsDefaultValueDifferentThanDefault()); }); diff --git a/SysML2.NET.Extensions.Tests/Utilities/StreamExtensionsTestFixture.cs b/SysML2.NET.Extensions.Tests/Utilities/StreamExtensionsTestFixture.cs index c22ad5641..0aea3db58 100644 --- a/SysML2.NET.Extensions.Tests/Utilities/StreamExtensionsTestFixture.cs +++ b/SysML2.NET.Extensions.Tests/Utilities/StreamExtensionsTestFixture.cs @@ -38,10 +38,8 @@ public async Task Verify_that_ReadAllBytesAsync_throws_on_null_stream() { Stream stream = null; - var ex = Assert.ThrowsAsync(async () => - await stream.ReadAllBytesAsync(CancellationToken.None)); - - Assert.That(ex!.ParamName, Is.EqualTo("stream")); + await Assert.ThatAsync(async () => await stream.ReadAllBytesAsync(CancellationToken.None), + Throws.ArgumentNullException.With.Property(nameof(ArgumentNullException.ParamName)).EqualTo("stream")); } [Test] From a2bac77a61bda9d767069eb269d69e1390209f70 Mon Sep 17 00:00:00 2001 From: samatstarion Date: Fri, 6 Nov 2026 10:57:45 +0100 Subject: [PATCH 2/2] [Remove] code generator copies of uml4net 9.2 queries; keep name ordering only for the MessagePack template helper --- .../ClassHelperTestFixture.cs | 12 +----- .../PropertyHelperTestFixture.cs | 2 +- .../Extensions/ClassExtensions.cs | 40 ------------------- .../Extensions/PropertyExtension.cs | 31 -------------- .../HandleBarHelpers/ClassHelper.cs | 12 ------ .../HandleBarHelpers/PropertyHelper.cs | 6 +-- 6 files changed, 5 insertions(+), 98 deletions(-) diff --git a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs index 5eea88b02..f342a863f 100644 --- a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs +++ b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/ClassHelperTestFixture.cs @@ -135,22 +135,12 @@ public void Verify_that_WriteCountAllNonDerivedProperties_writes_numeric_count() Assert.That(count, Is.GreaterThanOrEqualTo(0)); } - [Test] - public void Verify_that_QueryAllNonDerivedNonRedefinedProperties_does_not_throw() - { - var testClass = this.allClasses.First(c => !c.IsAbstract && CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(c).Count > 0); - - Assert.That(() => this.RenderWithClassContext( - "{{#Class.QueryAllNonDerivedNonRedefinedProperties}}item{{/Class.QueryAllNonDerivedNonRedefinedProperties}}", - testClass), Throws.Nothing); - } - [Test] public void Verify_that_QueryAllNonDerivedNonRedefinedProperties_returns_expected_count() { var testClass = this.allClasses.First(c => !c.IsAbstract); - var expectedCount = CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(testClass).Count; + var expectedCount = testClass.QueryAllNonDerivedNonRedefinedProperties().Count; var countResult = this.RenderWithClassContext("{{Class.WriteCountAllNonDerivedNonRedefinedProperties}}", testClass); var actualCount = int.Parse(countResult.Trim()); diff --git a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs index 64ac2d211..ecdc7a98b 100644 --- a/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs +++ b/SysML2.NET.CodeGenerator.Tests/HandleBarHelpers/PropertyHelperTestFixture.cs @@ -148,7 +148,7 @@ public void Verify_that_WriteForDTOClass_generates_property_for_each_class() { foreach (var @class in this.allClasses.Where(c => !c.IsAbstract).Take(5)) { - var properties = CodeGenerator.Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(@class); + var properties = @class.QueryAllNonDerivedNonRedefinedProperties(); foreach (var property in properties.Take(3)) { diff --git a/SysML2.NET.CodeGenerator/Extensions/ClassExtensions.cs b/SysML2.NET.CodeGenerator/Extensions/ClassExtensions.cs index 9d8e0a0e9..ddbab62c8 100644 --- a/SysML2.NET.CodeGenerator/Extensions/ClassExtensions.cs +++ b/SysML2.NET.CodeGenerator/Extensions/ClassExtensions.cs @@ -9,7 +9,6 @@ namespace SysML2.NET.CodeGenerator.Extensions { - using System.Collections.ObjectModel; using System.Linq; using uml4net.Classification; @@ -21,45 +20,6 @@ namespace SysML2.NET.CodeGenerator.Extensions /// public static class ClassExtensions { - /// - /// Queries all the properties that are implemented by the class directly or through superclasses - /// or interface implementations EXCLUDING IsDerived - /// - /// - /// The from which to query the properties - /// - /// - /// A of - /// - public static ReadOnlyCollection QueryAllNonDerivedProperties(this IClass @class) - { - var properties = @class.QueryAllProperties() - .Where(x => !x.IsDerived); - - return properties.ToList().AsReadOnly(); - } - - /// - /// Queries all the properties that are implemented by the class directly or through superclasses - /// or interface implementations EXCLUDING IsDerived and EXCLUDING properties that have been - /// redefined in the context of the current class - /// - /// - /// The from which to query the properties - /// - /// - /// A of - /// - public static ReadOnlyCollection QueryAllNonDerivedNonRedefinedProperties(this IClass @class) - { - var properties = @class.QueryAllProperties() - .Where(x => !x.IsDerived) - .Where(x => !x.TryQueryRedefinedByProperty(@class, out _)) - .OrderBy(x => x.Name); - - return properties.ToList().AsReadOnly(); - } - /// /// Counts and returns to amount of non derived properties /// diff --git a/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs b/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs index aaf69b637..fbfb9d1c6 100644 --- a/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs +++ b/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs @@ -24,37 +24,6 @@ namespace SysML2.NET.CodeGenerator.Extensions /// public static class PropertyExtension { - /// - /// Asserts that the is an enum type with a default value provided - /// - /// The to assert - /// True if the have a default value for an enum - public static bool QueryIsEnumPropertyWithDefaultValue(this IProperty property) - { - ArgumentNullException.ThrowIfNull(property); - - if (!property.QueryIsEnum()) - { - return false; - } - - var defaultValue = property.QueryDefaultValueAsString(); - - if (defaultValue == "null") - { - return false; - } - - var valueSpecification = property.DefaultValue.FirstOrDefault(); - - if (valueSpecification is IInstanceValue instanceValue) - { - return instanceValue.Instance is IEnumerationLiteral; - } - - return false; - } - /// /// Gets the name of the property. /// diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs index 881ad0ca6..0ede78f93 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs @@ -159,18 +159,6 @@ public static void RegisterClassHelper(this IHandlebars handlebars) writer.WriteSafeString(@class.CountAllNonDerivedProperties()); }); - // Queries all the properties that are non derived and not redefined in the - // context of the current class - handlebars.RegisterHelper("Class.QueryAllNonDerivedNonRedefinedProperties", (context, _) => - { - if (!(context.Value is IClass @class)) - { - throw new ArgumentException("#Class.QueryAllNonDerivedNonRedefinedProperties: supposed to be IClass"); - } - - return Extensions.ClassExtensions.QueryAllNonDerivedNonRedefinedProperties(@class); - }); - // writes the count of non-derived and non Redefined properties of the IClass handlebars.RegisterHelper("Class.WriteCountAllNonDerivedNonRedefinedProperties", (writer, context, _) => { diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs index f9c7ce368..3adf362cd 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs @@ -247,7 +247,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) if (!isRedefinedPropertyInContext) { - if (PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property)) + if (property.QueryIsEnumPropertyWithDefaultValue()) { sb.Append($" = {property.Type.Name.CapitalizeFirstLetter()}.{property.QueryDefaultValueAsString().CapitalizeFirstLetter()};"); } @@ -475,7 +475,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) if ((!property.IsDerived || property.IsDerivedUnion) && !isRedefinedPropertyInContext) { - if (PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property)) + if (property.QueryIsEnumPropertyWithDefaultValue()) { sb.Append($" = {property.Type.Name.CapitalizeFirstLetter()}.{property.QueryDefaultValueAsString().CapitalizeFirstLetter()};"); } @@ -1052,7 +1052,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) } return property.QueryIsEnum() - ? PropertyExtension.QueryIsEnumPropertyWithDefaultValue(property) + ? property.QueryIsEnumPropertyWithDefaultValue() : (property.QueryHasDefaultValue() && property.QueryIsDefaultValueDifferentThanDefault()); });