From 5b86b324d84da94832c29cbc2153b24001f7903b Mon Sep 17 00:00:00 2001 From: samatstarion Date: Fri, 23 Jan 2026 13:41:19 +0100 Subject: [PATCH] [Update] dependencies and refactor using explicit reference to extension method --- .../SysML2.NET.CodeGenerator.Tests.csproj | 6 +-- .../Extensions/PropertyExtension.cs | 10 ----- .../HandleBarHelpers/ClassHelper.cs | 12 +++--- .../HandleBarHelpers/PropertyHelper.cs | 40 +++++++++---------- .../SysML2.NET.CodeGenerator.csproj | 6 +-- .../SysML2.NET.Dal.Tests.csproj | 6 +-- .../SysML2.NET.Extensions.Tests.csproj | 6 +-- .../SysML2.NET.Serializer.Json.Tests.csproj | 6 +-- .../SysML2.NET.Serializer.Json.csproj | 4 +- SysML2.NET/SysML2.NET.csproj | 2 +- 10 files changed, 44 insertions(+), 54 deletions(-) diff --git a/SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj b/SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj index e6f43823..40aeaff6 100644 --- a/SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj +++ b/SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj @@ -1589,11 +1589,11 @@ - + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs b/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs index 33f9fe85..effa1db2 100644 --- a/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs +++ b/SysML2.NET.CodeGenerator/Extensions/PropertyExtension.cs @@ -32,16 +32,6 @@ namespace SysML2.NET.CodeGenerator.Extensions /// public static class PropertyExtension { - /// - /// Asserts that the current is C# nullable and not a string primitive - /// - /// The to assert - /// True is the is C# nullable and not a string - public static bool QueryIsNullableAndNotString(this IProperty property) - { - return property.QueryIsNullable() && property.QueryCSharpTypeName() != "string"; - } - /// /// Asserts that the is an enum type with a default value provided /// diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs index 85d5fd32..acaf3b0b 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/ClassHelper.cs @@ -58,7 +58,7 @@ public static void RegisterClassHelper(this IHandlebars handlebars) foreach (var prop in allProperties.Where(x => x.QueryIsEnum())) { - uniqueNamespaces.Add(prop.Type.QueryNamespace()); + uniqueNamespaces.Add(Extensions.NamedElementExtensions.QueryNamespace(prop.Type)); } var orderedNamespaces = uniqueNamespaces.Order().ToList(); @@ -76,7 +76,7 @@ public static void RegisterClassHelper(this IHandlebars handlebars) throw new ArgumentException("#Class.WriteEnumerationNameSpace supposed to be an IEnumeration"); } - writer.WriteSafeString($"using SysML2.NET.Core.{enumeration.QueryNamespace()};{Environment.NewLine}"); + writer.WriteSafeString($"using SysML2.NET.Core.{Extensions.NamedElementExtensions.QueryNamespace(enumeration)};{Environment.NewLine}"); }); handlebars.RegisterHelper("Class.WriteNameSpaces", (writer, context, arguments) => @@ -99,7 +99,7 @@ public static void RegisterClassHelper(this IHandlebars handlebars) foreach (var superClass in superClasses) { - uniqueNamespaces.Add(superClass.QueryNamespace()); + uniqueNamespaces.Add(Extensions.NamedElementExtensions.QueryNamespace(superClass)); } if (namespacePrefix == "POCO") @@ -108,7 +108,7 @@ public static void RegisterClassHelper(this IHandlebars handlebars) foreach (var prop in allProperties.Where(x => x.QueryIsReferenceProperty())) { - uniqueNamespaces.Add(prop.Type.QueryNamespace()); + uniqueNamespaces.Add(Extensions.NamedElementExtensions.QueryNamespace(prop.Type)); } var interfaceDerivedProperties = @@ -120,13 +120,13 @@ public static void RegisterClassHelper(this IHandlebars handlebars) { if (interfaceDerivedProperty.Possessor is INamedElement owner) { - var @namespace = owner.QueryNamespace(); + var @namespace = Extensions.NamedElementExtensions.QueryNamespace(owner); uniqueNamespaces.Add(@namespace); } } } - uniqueNamespaces.Remove(@class.QueryNamespace()); + uniqueNamespaces.Remove(Extensions.NamedElementExtensions.QueryNamespace(@class)); var orderedNamespaces = uniqueNamespaces.Order().ToList(); foreach (var orderedNamespace in orderedNamespaces) diff --git a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs index ad233626..463e8216 100644 --- a/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs +++ b/SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs @@ -73,7 +73,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) { sb.Append($"{property.QueryCSharpTypeName()}"); - if (property.QueryIsNullableAndNotString()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property)) { sb.Append('?'); } @@ -92,7 +92,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) { sb.Append("Guid"); - if (property.QueryIsNullableAndNotString()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property)) { sb.Append('?'); } @@ -154,7 +154,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) { sb.Append($"{property.QueryCSharpTypeName()}"); - if (property.QueryIsNullableAndNotString()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property)) { sb.Append('?'); } @@ -173,7 +173,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) { sb.Append("Guid"); - if (property.QueryIsNullableAndNotString()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property)) { sb.Append('?'); } @@ -192,9 +192,9 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) var owner = (INamedElement)property.Owner; propertyName = $"I{owner.Name}.{propertyName}"; - var ownerNamespace = owner.QueryNamespace(); + var ownerNamespace = Extensions.NamedElementExtensions.QueryNamespace(owner); - if (ownerNamespace != classContext.QueryNamespace()) + if (ownerNamespace != Extensions.NamedElementExtensions.QueryNamespace(classContext)) { propertyName = $"{ownerNamespace}.{propertyName}"; } @@ -300,7 +300,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) } else { - if (property.QueryIsNullableAndNotString() && !property.QueryIsReferenceProperty()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property) && !property.QueryIsReferenceProperty()) { sb.Append($"{typeName}? "); } @@ -371,7 +371,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) } else { - if (property.QueryIsNullableAndNotString() && !property.QueryIsReferenceProperty()) + if (uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(property) && !property.QueryIsReferenceProperty()) { sb.Append($"{typeName}? "); } @@ -391,9 +391,9 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) var owner = (INamedElement)property.Owner; propertyName = $"I{owner.Name}.{propertyName}"; - var ownerNamespace = owner.QueryNamespace(); + var ownerNamespace = Extensions.NamedElementExtensions.QueryNamespace(owner); - if (ownerNamespace != classContext.QueryNamespace()) + if (ownerNamespace != Extensions.NamedElementExtensions.QueryNamespace(classContext)) { propertyName = $"{ownerNamespace}.{propertyName}"; } @@ -612,7 +612,7 @@ public static void RegisterPropertyHelper(this IHandlebars handlebars) if (property.TryQueryRedefinedByProperty(generatedClass, out var redefinitionProperty) && redefinitionProperty.Name == property.Name) { var owner = (INamedElement)property.Owner; - writer.WriteSafeString($"((SysML2.NET.Core.DTO.{owner.QueryNamespace()}.I{owner.Name}){variableName}).{propertyName}"); + writer.WriteSafeString($"((SysML2.NET.Core.DTO.{Extensions.NamedElementExtensions.QueryNamespace(owner)}.I{owner.Name}){variableName}).{propertyName}"); } else { @@ -645,7 +645,7 @@ private static string GetRedefinedPropertyGetterImplementationForDto(IProperty r if (redefinition.TryQueryRedefinedByProperty(context, out _)) { var owner = (INamedElement)redefinition.Owner; - redefinitionPropertyName = $"((SysML2.NET.Core.DTO.{owner.QueryNamespace()}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; + redefinitionPropertyName = $"((SysML2.NET.Core.DTO.{Extensions.NamedElementExtensions.QueryNamespace(owner)}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; } else { @@ -659,12 +659,12 @@ private static string GetRedefinedPropertyGetterImplementationForDto(IProperty r if (redefinedProperty.QueryIsEnumerable() && !redefinition.QueryIsEnumerable()) { - return redefinition.QueryIsNullableAndNotString() + return uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(redefinition) ? $"{redefinitionPropertyName}.HasValue ? [{redefinitionPropertyName}.Value] : [];" : $"[{redefinitionPropertyName}];"; } - return redefinition.QueryIsNullableAndNotString() + return uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(redefinition) ? $"{redefinitionPropertyName}.HasValue ? {redefinitionPropertyName}.Value : {(redefinedProperty.QueryIsReferenceProperty() ? "Guid.Empty" : "default")};" : $"{redefinitionPropertyName};"; } @@ -675,7 +675,7 @@ private static string GetRedefinedPropertyGetterImplementationForDto(IProperty r /// The redefined property /// The property that redefines /// Gets the context - /// The getter imlementation + /// The getter implementation private static string GetRedefinedPropertyGetterImplementationForPoco(IProperty redefinedProperty, IProperty redefinition, IClass context) { string redefinitionPropertyName; @@ -683,7 +683,7 @@ private static string GetRedefinedPropertyGetterImplementationForPoco(IProperty if (redefinition.TryQueryRedefinedByProperty(context, out _)) { var owner = (INamedElement)redefinition.Owner; - redefinitionPropertyName = $"((SysML2.NET.Core.POCO.{owner.QueryNamespace()}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; + redefinitionPropertyName = $"((SysML2.NET.Core.POCO.{Extensions.NamedElementExtensions.QueryNamespace(owner)}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; } else { @@ -707,12 +707,12 @@ private static string GetRedefinedPropertyGetterImplementationForPoco(IProperty return $"string.IsNullOrWhiteSpace({redefinitionPropertyName}) ? [{redefinitionPropertyName}] : [];"; } - return redefinition.QueryIsNullableAndNotString() + return uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(redefinition) ? $"{redefinitionPropertyName}.HasValue ? [{redefinitionPropertyName}.Value] : [];" : $"[{redefinitionPropertyName}];"; } - return redefinition.QueryIsNullableAndNotString() && !redefinedProperty.QueryIsReferenceProperty() + return uml4net.Extensions.PropertyExtensions.QueryIsNullableAndNotString(redefinition) && !redefinedProperty.QueryIsReferenceProperty() ? $"{redefinitionPropertyName}.HasValue ? {redefinitionPropertyName}.Value : default;" : $"{redefinitionPropertyName};"; } @@ -736,7 +736,7 @@ private static string GetRedefinedPropertySetterImplementationForDto(IProperty r if (redefinition.TryQueryRedefinedByProperty(context, out _)) { var owner = (INamedElement)redefinition.Owner; - redefinitionPropertyName = $"((SysML2.NET.Core.DTO.{owner.QueryNamespace()}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; + redefinitionPropertyName = $"((SysML2.NET.Core.DTO.{Extensions.NamedElementExtensions.QueryNamespace(owner)}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; } else { @@ -775,7 +775,7 @@ private static string GetRedefinedPropertySetterImplementationForPoco(IProperty if (redefinition.TryQueryRedefinedByProperty(context, out _)) { var owner = (INamedElement)redefinition.Owner; - redefinitionPropertyName = $"((SysML2.NET.Core.POCO.{owner.QueryNamespace()}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; + redefinitionPropertyName = $"((SysML2.NET.Core.POCO.{Extensions.NamedElementExtensions.QueryNamespace(owner)}.I{owner.Name})this).{redefinition.QueryPropertyNameBasedOnUmlProperties()}"; } else { diff --git a/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj b/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj index 978004e0..5e53a4cc 100644 --- a/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj +++ b/SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj @@ -27,9 +27,9 @@ - - - + + +