From f77b6aa4d89654b35fe6c1ebe82fc3b8cc3f66bf Mon Sep 17 00:00:00 2001 From: dalvarellos Date: Fri, 22 Nov 2024 14:53:51 -0300 Subject: [PATCH 1/8] Use collection for properties and pass context to called object --- .../GxClasses/Helpers/GxDynamicCall.cs | 86 +++++++------------ 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index d6af1f832..b3e5c0a83 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -1,20 +1,21 @@ -using GeneXus.Application; -using GeneXus.Metadata; -using GeneXus.Utils; using System; using System.Collections.Generic; using System.Reflection; +using GeneXus.Application; +using GeneXus.Metadata; +using GeneXus.Utils; namespace GeneXus.DynamicCall { - public class GxDynamicCall - { + public class GxDynamicCall + { private const string defaultMethod = "execute"; private Assembly _assembly; - private GxDynCallProperties _properties; + private readonly IGxContext _context; + private GXProperties _properties; private object _object; - public string ObjectName { get; set; } - public GxDynCallProperties Properties + public string ExternalName { get; set; } + public GXProperties Properties { get => _properties; set @@ -23,19 +24,20 @@ public GxDynCallProperties Properties } } - public GxDynamicCall() + public GxDynamicCall(IGxContext context) { - _assembly= null; - _properties = new GxDynCallProperties(); + _context = context; + _assembly = null; + _properties = new GXProperties(); _object = null; } - private void VerifyDefaultProperties() { - _properties.NameSpace = string.IsNullOrEmpty(_properties.NameSpace) ? "GeneXus.Programs" : _properties.NameSpace; - + private void VerifyDefaultProperties() + { + if (_assembly is null) { - if (string.IsNullOrEmpty(_properties.AssemblyName)) + if (string.IsNullOrEmpty(_properties.Get("AssemblyName"))) { _assembly = Assembly.GetCallingAssembly(); } @@ -43,7 +45,7 @@ private void VerifyDefaultProperties() { { try { - _assembly = Assembly.LoadFrom(_properties.AssemblyName); + _assembly = Assembly.LoadFrom(_properties.Get("AssemblyName")); } catch { @@ -63,24 +65,19 @@ public void Execute(ref IList parameters, out IList } } - public void Create( IList constructParms, out IList errors) + public void Create(IList constructParms, out IList errors) { errors = new GXBaseCollection(); string objectNameToInvoke; try { VerifyDefaultProperties(); - if (constructParms is null) - { - objectNameToInvoke = ObjectName; - } - else - { - objectNameToInvoke = _properties.ExternalName; - } + + objectNameToInvoke = ExternalName; + try { - Type objType = ClassLoader.FindType(objectNameToInvoke, _properties.NameSpace, objectNameToInvoke.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(objectNameToInvoke, objectNameToInvoke.ToLower().Trim(), _assembly); object[] constructorParameters; if (constructParms != null && constructParms.Count > 0) { @@ -89,13 +86,13 @@ public void Create( IList constructParms, out IList } else { - constructorParameters = new object[] { new GxContext() }; + constructorParameters = new object[] { _context }; } _object = Activator.CreateInstance(objType, constructorParameters); } catch (Exception e) { - GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection) errors); + GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection)errors); } } catch (Exception e) @@ -103,13 +100,13 @@ public void Create( IList constructParms, out IList GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection)errors); } } - public object Execute(ref IList parameters, GxDynCallMethodConf methodconfiguration , out IList errors) + public object Execute(ref IList parameters, GxDynCallMethodConf methodconfiguration, out IList errors) { object result; errors = new GXBaseCollection(); - IList outParms= new List(); + IList outParms = new List(); - string methodName = methodconfiguration.MethodName; + string methodName = methodconfiguration.MethodName; bool isStatic = methodconfiguration.IsStatic; if (!isStatic) @@ -118,7 +115,7 @@ public object Execute(ref IList parameters, GxDynCallMethodConf methodco { try { - outParms = ReflectionHelper.CallMethod(_object, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters); + outParms = ReflectionHelper.CallMethod(_object, string.IsNullOrEmpty(methodName) ? defaultMethod : methodName, parameters); } catch (Exception e) { @@ -133,7 +130,7 @@ public object Execute(ref IList parameters, GxDynCallMethodConf methodco else { VerifyDefaultProperties(); - Type objType = ClassLoader.FindType(_properties.ExternalName, _properties.NameSpace, _properties.ExternalName.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(ExternalName, ExternalName.ToLower().Trim(), _assembly); outParms = ReflectionHelper.CallMethod(objType, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters, isStatic); } if (outParms.Count > parameters.Count) @@ -169,25 +166,4 @@ public GxDynCallMethodConf() } } - - public class GxDynCallProperties - { - public string ExternalName - { - get; - set; - } - public string AssemblyName - { - get; - set; - } - public string NameSpace - { - get; - set; - } - - } -} - +} \ No newline at end of file From 2c5dd62c9c21560b95b7fd6e79a1f72b8508af82 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Tue, 26 Nov 2024 12:16:45 -0300 Subject: [PATCH 2/8] Restore GxDynCallProperties for compatibility with previous version of GenexsCore Module. --- .../GxClasses/Helpers/GxDynamicCall.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index b3e5c0a83..d47c457a3 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -164,6 +164,23 @@ public GxDynCallMethodConf() IsStatic = false; MethodName = "execute"; } - + } + public class GxDynCallProperties + { + public string ExternalName + { + get; + set; + } + public string AssemblyName + { + get; + set; + } + public string NameSpace + { + get; + set; + } } } \ No newline at end of file From bd6d2864121775a7a3c94dae58f4ccc58d7b12a7 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 28 Nov 2024 10:10:40 -0300 Subject: [PATCH 3/8] Restore the ObjectName property and the default constructor to maintain backward compatibility with the GeneXus Core module. --- .../src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index d47c457a3..7c91b3f18 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -14,6 +14,9 @@ public class GxDynamicCall private readonly IGxContext _context; private GXProperties _properties; private object _object; + + [Obsolete("ObjectName is deprecated. Use ExternalName instead", false)] + public string ObjectName { get; set; } public string ExternalName { get; set; } public GXProperties Properties { @@ -23,6 +26,10 @@ public GXProperties Properties _properties = Properties; } } + public GxDynamicCall() + { + _properties = new GXProperties(); + } public GxDynamicCall(IGxContext context) { From 08c0b552e7950ac6cf58630557c675839660a41b Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 28 Nov 2024 10:23:14 -0300 Subject: [PATCH 4/8] Restore Properties property for backward compatibility. --- .../GxClasses/Helpers/GxDynamicCall.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index 7c91b3f18..11f40a3b5 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -12,13 +12,16 @@ public class GxDynamicCall private const string defaultMethod = "execute"; private Assembly _assembly; private readonly IGxContext _context; - private GXProperties _properties; + private GXProperties _extendedProperties; + private GxDynCallProperties _properties; private object _object; [Obsolete("ObjectName is deprecated. Use ExternalName instead", false)] public string ObjectName { get; set; } public string ExternalName { get; set; } - public GXProperties Properties + + [Obsolete("Properties is deprecated. Use ExtendedProperties instead", false)] + public GxDynCallProperties Properties { get => _properties; set @@ -26,16 +29,27 @@ public GXProperties Properties _properties = Properties; } } + + public GXProperties ExtendedProperties + { + get => _extendedProperties; + set + { + _extendedProperties = ExtendedProperties; + } + } public GxDynamicCall() { - _properties = new GXProperties(); + _extendedProperties = new GXProperties(); + _properties = new GxDynCallProperties(); } public GxDynamicCall(IGxContext context) { _context = context; _assembly = null; - _properties = new GXProperties(); + _extendedProperties = new GXProperties(); + _properties = new GxDynCallProperties(); _object = null; } @@ -44,7 +58,7 @@ private void VerifyDefaultProperties() if (_assembly is null) { - if (string.IsNullOrEmpty(_properties.Get("AssemblyName"))) + if (string.IsNullOrEmpty(_extendedProperties.Get("AssemblyName"))) { _assembly = Assembly.GetCallingAssembly(); } @@ -52,7 +66,7 @@ private void VerifyDefaultProperties() { try { - _assembly = Assembly.LoadFrom(_properties.Get("AssemblyName")); + _assembly = Assembly.LoadFrom(_extendedProperties.Get("AssemblyName")); } catch { From c88b65422cc37deb0ef0f70190c61a8931c62013 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Thu, 28 Nov 2024 10:28:40 -0300 Subject: [PATCH 5/8] Add generated files to ensure backward compatibility. --- .../GxClasses/Helpers/GxDynamicCall.cs | 4 +- .../Domain/type_SdtDynamicCall.cs | 196 ++++++++++++++++++ .../type_SdtDynamicCallMethodProperties.cs | 120 +++++++++++ .../type_SdtDynamicCallPropertiesNet.cs | 120 +++++++++++ 4 files changed, 438 insertions(+), 2 deletions(-) create mode 100644 dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs create mode 100644 dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs create mode 100644 dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index 11f40a3b5..ae9fcbdb2 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -16,11 +16,11 @@ public class GxDynamicCall private GxDynCallProperties _properties; private object _object; - [Obsolete("ObjectName is deprecated. Use ExternalName instead", false)] + //[Obsolete("ObjectName is deprecated. Use ExternalName instead", false)] public string ObjectName { get; set; } public string ExternalName { get; set; } - [Obsolete("Properties is deprecated. Use ExtendedProperties instead", false)] + //[Obsolete("Properties is deprecated. Use ExtendedProperties instead", false)] public GxDynCallProperties Properties { get => _properties; diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs new file mode 100644 index 000000000..63e9ed510 --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs @@ -0,0 +1,196 @@ +/* + File: genexus.common.type_SdtDynamicCall + Description: DynamicCall + Author: GeneXus .NET Generator version 18_0_11-185337 + Generated on: 11/28/2024 9:54:49.46 + Program type: Callable routine + Main DBMS: SQL Server +*/ +using System; +using System.Collections; +using System.Xml.Serialization; +using GeneXus.Application; +using GeneXus.Utils; +namespace GeneXus.Core.genexus.common +{ + [Serializable] + public class SdtDynamicCall : GxUserType, IGxExternalObject + { + public SdtDynamicCall( ) + { + /* Constructor for serialization */ + } + + public SdtDynamicCall( IGxContext context ) + { + this.context = context; + initialize(); + } + + private static Hashtable mapper; + public override string JsonMap( string value ) + { + if ( mapper == null ) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public void execute( ref GxSimpleCollection gxTp_Parameters , + out GXBaseCollection gxTp_Errors ) + { + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + System.Collections.Generic.IList externalParm0; + System.Collections.Generic.IList externalParm1; + externalParm0 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), gxTp_Parameters.ExternalInstance); + GeneXus_Common_DynamicCall_externalReference.Execute(ref externalParm0, out externalParm1); + gxTp_Parameters.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm0); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm1); + return ; + } + + public object execute( ref GxSimpleCollection gxTp_Parameters , + GeneXus.Core.genexus.common.SdtDynamicCallMethodProperties gxTp_MethodInfo , + out GXBaseCollection gxTp_Errors ) + { + object returnexecute; + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + object externalParm0; + System.Collections.Generic.IList externalParm1; + GeneXus.DynamicCall.GxDynCallMethodConf externalParm2; + System.Collections.Generic.IList externalParm3; + externalParm1 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), gxTp_Parameters.ExternalInstance); + externalParm2 = (GeneXus.DynamicCall.GxDynCallMethodConf)(gxTp_MethodInfo.ExternalInstance); + externalParm0 = GeneXus_Common_DynamicCall_externalReference.Execute(ref externalParm1, externalParm2, out externalParm3); + returnexecute = (object)(externalParm0); + gxTp_Parameters.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm1); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm3); + return returnexecute ; + } + + public void create( GxSimpleCollection gxTp_Parameters , + out GXBaseCollection gxTp_Errors ) + { + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + System.Collections.Generic.IList externalParm0; + System.Collections.Generic.IList externalParm1; + externalParm0 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), gxTp_Parameters.ExternalInstance); + GeneXus_Common_DynamicCall_externalReference.Create(externalParm0, out externalParm1); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm1); + return ; + } + + public void setoption( ref string gxTp_ObjectName , + ref string gxTp_CallOption , + ref string gxTp_Value ) + { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + return ; + } + + public string gxTpr_Objectname + { + get { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + return GeneXus_Common_DynamicCall_externalReference.ObjectName ; + } + + set { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + GeneXus_Common_DynamicCall_externalReference.ObjectName = value; + SetDirty("Objectname"); + } + + } + + public GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet gxTpr_Net + { + get { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet intValue; + intValue = new GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet(context); + GeneXus.DynamicCall.GxDynCallProperties externalParm0; + externalParm0 = GeneXus_Common_DynamicCall_externalReference.Properties; + intValue.ExternalInstance = externalParm0; + return intValue ; + } + + set { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet intValue; + GeneXus.DynamicCall.GxDynCallProperties externalParm1; + intValue = value; + externalParm1 = (GeneXus.DynamicCall.GxDynCallProperties)(intValue.ExternalInstance); + GeneXus_Common_DynamicCall_externalReference.Properties = externalParm1; + SetDirty("Net"); + } + + } + + public Object ExternalInstance + { + get { + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + return GeneXus_Common_DynamicCall_externalReference ; + } + + set { + GeneXus_Common_DynamicCall_externalReference = (GeneXus.DynamicCall.GxDynamicCall)(value); + } + + } + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo + { + get { + return _typeProps ; + } + + set { + _typeProps = value ; + } + + } + + public void initialize( ) + { + return ; + } + + protected GeneXus.DynamicCall.GxDynamicCall GeneXus_Common_DynamicCall_externalReference=null ; + } + +} diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs new file mode 100644 index 000000000..60e5c67a3 --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs @@ -0,0 +1,120 @@ +/* + File: genexus.common.type_SdtDynamicCallMethodProperties + Description: DynamicCallMethodProperties + Author: GeneXus .NET Generator version 18_0_11-185337 + Generated on: 11/28/2024 9:54:49.46 + Program type: Callable routine + Main DBMS: SQL Server +*/ +using System; +using System.Collections; +using System.Xml.Serialization; +using GeneXus.Application; +using GeneXus.Utils; +namespace GeneXus.Core.genexus.common +{ + [Serializable] + public class SdtDynamicCallMethodProperties : GxUserType, IGxExternalObject + { + public SdtDynamicCallMethodProperties( ) + { + /* Constructor for serialization */ + } + + public SdtDynamicCallMethodProperties( IGxContext context ) + { + this.context = context; + initialize(); + } + + private static Hashtable mapper; + public override string JsonMap( string value ) + { + if ( mapper == null ) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public bool gxTpr_Isstatic + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference.IsStatic ; + } + + set { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + GeneXus_Common_DynamicCallMethodProperties_externalReference.IsStatic = value; + SetDirty("Isstatic"); + } + + } + + public string gxTpr_Methodname + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference.MethodName ; + } + + set { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + GeneXus_Common_DynamicCallMethodProperties_externalReference.MethodName = value; + SetDirty("Methodname"); + } + + } + + public Object ExternalInstance + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference ; + } + + set { + GeneXus_Common_DynamicCallMethodProperties_externalReference = (GeneXus.DynamicCall.GxDynCallMethodConf)(value); + } + + } + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo + { + get { + return _typeProps ; + } + + set { + _typeProps = value ; + } + + } + + public void initialize( ) + { + return ; + } + + protected GeneXus.DynamicCall.GxDynCallMethodConf GeneXus_Common_DynamicCallMethodProperties_externalReference=null ; + } + +} diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs new file mode 100644 index 000000000..a2843b72b --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs @@ -0,0 +1,120 @@ +/* + File: genexus.common.type_SdtDynamicCallPropertiesNet + Description: DynamicCallPropertiesNet + Author: GeneXus .NET Generator version 18_0_11-185337 + Generated on: 11/28/2024 9:54:49.49 + Program type: Callable routine + Main DBMS: SQL Server +*/ +using System; +using System.Collections; +using System.Xml.Serialization; +using GeneXus.Application; +using GeneXus.Utils; +namespace GeneXus.Core.genexus.common +{ + [Serializable] + public class SdtDynamicCallPropertiesNet : GxUserType, IGxExternalObject + { + public SdtDynamicCallPropertiesNet( ) + { + /* Constructor for serialization */ + } + + public SdtDynamicCallPropertiesNet( IGxContext context ) + { + this.context = context; + initialize(); + } + + private static Hashtable mapper; + public override string JsonMap( string value ) + { + if ( mapper == null ) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public string gxTpr_Externalname + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference.ExternalName ; + } + + set { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + GeneXus_Common_DynamicCallPropertiesNet_externalReference.ExternalName = value; + SetDirty("Externalname"); + } + + } + + public string gxTpr_Assemblyname + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference.AssemblyName ; + } + + set { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + GeneXus_Common_DynamicCallPropertiesNet_externalReference.AssemblyName = value; + SetDirty("Assemblyname"); + } + + } + + public Object ExternalInstance + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference ; + } + + set { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = (GeneXus.DynamicCall.GxDynCallProperties)(value); + } + + } + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo + { + get { + return _typeProps ; + } + + set { + _typeProps = value ; + } + + } + + public void initialize( ) + { + return ; + } + + protected GeneXus.DynamicCall.GxDynCallProperties GeneXus_Common_DynamicCallPropertiesNet_externalReference=null ; + } + +} From 58ef1f4407a5a58ea8a7fba29a54d3d776e3c088 Mon Sep 17 00:00:00 2001 From: dalvarellos Date: Mon, 2 Jun 2025 13:11:34 -0300 Subject: [PATCH 6/8] Refactor GxDynamicCall: fix props, improve assembly loading Added missing using directives and a public AssemblyName constant. Fixed property setters for Properties and ExtendedProperties. Enhanced VerifyDefaultProperties to use the AssemblyName constant, improved cross-platform assembly loading logic, and added better exception handling for load failures. These changes improve correctness, maintainability, and compatibility. --- .../GxClasses/Helpers/GxDynamicCall.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index ae9fcbdb2..5a4fbbd28 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -1,15 +1,18 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Reflection; using GeneXus.Application; using GeneXus.Metadata; using GeneXus.Utils; +using GxClasses.Helpers; namespace GeneXus.DynamicCall { public class GxDynamicCall { private const string defaultMethod = "execute"; + public const string AssemblyName = "AssemblyName"; private Assembly _assembly; private readonly IGxContext _context; private GXProperties _extendedProperties; @@ -26,7 +29,7 @@ public GxDynCallProperties Properties get => _properties; set { - _properties = Properties; + _properties = value; } } @@ -35,7 +38,7 @@ public GXProperties ExtendedProperties get => _extendedProperties; set { - _extendedProperties = ExtendedProperties; + _extendedProperties = value; } } public GxDynamicCall() @@ -58,24 +61,35 @@ private void VerifyDefaultProperties() if (_assembly is null) { - if (string.IsNullOrEmpty(_extendedProperties.Get("AssemblyName"))) + if (string.IsNullOrEmpty(_extendedProperties.Get(AssemblyName))) { +#if NETCORE + var stackTrace = new StackTrace(); + var frame = stackTrace.GetFrame(2); + var method = frame.GetMethod(); + var assembly = method.DeclaringType.Assembly; + _assembly = assembly; +#else _assembly = Assembly.GetCallingAssembly(); +#endif } else { try { - _assembly = Assembly.LoadFrom(_extendedProperties.Get("AssemblyName")); +#if NETCORE + _assembly = AssemblyLoader.LoadAssembly(new AssemblyName(_extendedProperties.Get(AssemblyName))); +#else + _assembly = Assembly.LoadFrom(_extendedProperties.Get(AssemblyName) + ".dll" ); +#endif } - catch + catch (Exception e) { - throw; + throw new InvalidOperationException("Error loading assembly: " + _extendedProperties.Get(AssemblyName), e); } } } } - public void Execute(ref IList parameters, out IList errors) { Create(null, out errors); From 7e9bc2e2121d51a9959e8115a698655bde7de553 Mon Sep 17 00:00:00 2001 From: dalvarellos Date: Tue, 3 Jun 2025 10:22:50 -0300 Subject: [PATCH 7/8] Adjust stack frame index for correct assembly retrieval Changed stackTrace.GetFrame from (2) to (5) when retrieving the calling method's assembly in .NET Core. This ensures the correct assembly is identified by accounting for changes in the call stack structure. --- dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index 5a4fbbd28..c6fe7d0f4 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -65,7 +65,7 @@ private void VerifyDefaultProperties() { #if NETCORE var stackTrace = new StackTrace(); - var frame = stackTrace.GetFrame(2); + var frame = stackTrace.GetFrame(5); var method = frame.GetMethod(); var assembly = method.DeclaringType.Assembly; _assembly = assembly; From c73b059bd0031f30354a457ca7bc757c7b4b8475 Mon Sep 17 00:00:00 2001 From: dalvarellos Date: Tue, 3 Jun 2025 14:10:59 -0300 Subject: [PATCH 8/8] Refactor GxDynamicCall to handle assemblies/namespaces Refactor GxDynamicCall to introduce explicit AssemblyNameProperty and NamespaceProperty constants, with a default namespace ("GeneXus.Programs"). Update logic to allow dynamic specification of assembly and namespace via properties, and adjust object name resolution and ClassLoader usage accordingly. Improves flexibility and clarity in dynamic invocation. --- .../GxClasses/Helpers/GxDynamicCall.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index c6fe7d0f4..2b274d300 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -6,13 +6,16 @@ using GeneXus.Metadata; using GeneXus.Utils; using GxClasses.Helpers; +using Microsoft.IdentityModel.Tokens; namespace GeneXus.DynamicCall { public class GxDynamicCall { private const string defaultMethod = "execute"; - public const string AssemblyName = "AssemblyName"; + private const string AssemblyNameProperty = "AssemblyName"; + private const string NamespaceProperty = "Namespace"; + private const string DefaultNamespace = "GeneXus.Programs"; private Assembly _assembly; private readonly IGxContext _context; private GXProperties _extendedProperties; @@ -61,7 +64,7 @@ private void VerifyDefaultProperties() if (_assembly is null) { - if (string.IsNullOrEmpty(_extendedProperties.Get(AssemblyName))) + if (string.IsNullOrEmpty(_extendedProperties.Get(AssemblyNameProperty))) { #if NETCORE var stackTrace = new StackTrace(); @@ -78,14 +81,14 @@ private void VerifyDefaultProperties() try { #if NETCORE - _assembly = AssemblyLoader.LoadAssembly(new AssemblyName(_extendedProperties.Get(AssemblyName))); + _assembly = AssemblyLoader.LoadAssembly(new AssemblyName(_extendedProperties.Get(AssemblyNameProperty))); #else - _assembly = Assembly.LoadFrom(_extendedProperties.Get(AssemblyName) + ".dll" ); + _assembly = Assembly.LoadFrom(_extendedProperties.Get(AssemblyNameProperty) + ".dll" ); #endif } catch (Exception e) { - throw new InvalidOperationException("Error loading assembly: " + _extendedProperties.Get(AssemblyName), e); + throw new InvalidOperationException("Error loading assembly: " + _extendedProperties.Get(AssemblyNameProperty), e); } } } @@ -108,11 +111,11 @@ public void Create(IList constructParms, out IList { VerifyDefaultProperties(); - objectNameToInvoke = ExternalName; + objectNameToInvoke = string.IsNullOrEmpty(_extendedProperties.Get(NamespaceProperty)) ? DefaultNamespace + "." + ExternalName.ToLower().Trim() : _extendedProperties.Get(NamespaceProperty) + "." + ExternalName.ToLower().Trim(); try { - Type objType = ClassLoader.FindType(objectNameToInvoke, objectNameToInvoke.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(_assembly.GetName().Name, string.IsNullOrEmpty(_extendedProperties.Get(NamespaceProperty))? DefaultNamespace : _extendedProperties.Get(NamespaceProperty), ExternalName.ToLower().Trim(), _assembly); object[] constructorParameters; if (constructParms != null && constructParms.Count > 0) {