From b987f54f593b29be9c047bbe81160aeef0187beb Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Fri, 25 Mar 2022 13:09:50 -0300 Subject: [PATCH 1/8] Implementation of a external object to do dinamics calls --- .../GxClasses/Services/ReflectionHelper.cs | 89 +++++++-- .../dotnet/GXDynamicCall/GXDynamicCall.csproj | 19 ++ .../dotnet/GXDynamicCall/GxDynamicCall.cs | 175 ++++++++++++++++++ 3 files changed, 269 insertions(+), 14 deletions(-) create mode 100644 dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj create mode 100644 dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs diff --git a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs index c500e40b6..f9bc09fb7 100644 --- a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs +++ b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs @@ -13,8 +13,8 @@ namespace GeneXus.Application { public class ReflectionHelper - { - const string ISO_8601_TIME_SEPARATOR= "T"; + { + const string ISO_8601_TIME_SEPARATOR = "T"; const string ISO_8601_TIME_SEPARATOR_1 = ":"; public static void CallBCMethod(object instance, String methodName, IList inParametersValues) { @@ -42,17 +42,42 @@ public static Dictionary CallMethodPattern(object instance, Stri MethodInfo methodInfo = instanceType.GetMethod(memberInfo.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); return CallMethodImpl(instance, methodInfo, parameters, context); } - public static Dictionary CallMethod(object instance, String methodName, IDictionary parameters, IGxContext context=null) + + public static Dictionary CallMethod(object instance, String methodName, IDictionary parameters, IGxContext context = null) { MethodInfo methodInfo = instance.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); return CallMethodImpl(instance, methodInfo, parameters, context); } + public static IList CallMethod(object instanceOrType, String methodName, IList parameters, bool isStatic = false, IGxContext context = null) + { + MethodInfo methodInfo; + object instance = null; + if (isStatic) + { + methodInfo = ((Type)instanceOrType).GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase); + } + else + { + + methodInfo = instanceOrType.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); + instance = instanceOrType; + } + return CallMethodImpl(instance, methodInfo, parameters, context); + } static Dictionary CallMethodImpl(object instance, MethodInfo methodInfo, IDictionary parameters, IGxContext context) { object[] parametersForInvocation = ProcessParametersForInvoke(methodInfo, parameters, context); object returnParm = methodInfo.Invoke(instance, parametersForInvocation); return ProcessParametersAfterInvoke(methodInfo, parametersForInvocation, returnParm); } + static IList CallMethodImpl(object instance, MethodInfo methodInfo, IList parameters, IGxContext context) + { + object[] parametersForInvocation = ProcessParametersForInvoke(methodInfo, parameters, context); + object returnParm = methodInfo.Invoke(instance, parametersForInvocation); + IList parametersAfterInvoke = parametersForInvocation.ToList(); + parametersAfterInvoke.Add(returnParm); + return parametersAfterInvoke; + } public static bool MethodHasInputParameters(object instance, String methodName) { MethodInfo methodInfo = instance.GetType().GetMethod(methodName); @@ -69,16 +94,16 @@ public static bool MethodHasInputParameters(object instance, String methodName) private static object ConvertSingleJsonItem(object value, Type newType, IGxContext context) { - if (value!= null && value.GetType() == newType) + if (value != null && value.GetType() == newType) { return value; } else if (typeof(IGxJSONAble).IsAssignableFrom(newType)) { object TObject; - if (typeof(GxSilentTrnSdt).IsAssignableFrom(newType) && context!=null) + if (typeof(GxSilentTrnSdt).IsAssignableFrom(newType) && context != null) { - TObject = Activator.CreateInstance(newType, new object[] { context}); + TObject = Activator.CreateInstance(newType, new object[] { context }); } else { @@ -117,9 +142,9 @@ private static object ConvertSingleJsonItem(object value, Type newType, IGxConte } } - private static object ConvertStringToNewNonNullableType(object value, Type newType, IGxContext context=null) + private static object ConvertStringToNewNonNullableType(object value, Type newType, IGxContext context = null) { - + if (newType.IsArray) { // For comma separated list @@ -136,7 +161,7 @@ private static object ConvertStringToNewNonNullableType(object value, Type newTy return ConvertSingleJsonItem(value, newType, context); } - internal static object ConvertStringToNewType(object value, Type newType, IGxContext context=null) + internal static object ConvertStringToNewType(object value, Type newType, IGxContext context = null) { // If it's not a nullable type, just pass through the parameters to Convert.ChangeType if (newType.GetTypeInfo().IsGenericType && newType.GetGenericTypeDefinition() != null && newType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) @@ -153,9 +178,9 @@ internal static object ConvertStringToNewType(object value, Type newType, IGxCon public static Dictionary ParametersFormat(object instance, string methodName) { MethodInfo methodInfo = instance.GetType().GetMethod(methodName); - + Dictionary formatList = new Dictionary(); - var methodParameters = methodInfo.GetParameters(); + var methodParameters = methodInfo.GetParameters(); foreach (var methodParameter in methodParameters) { var gxParameterName = GxParameterName(methodParameter.Name); @@ -172,6 +197,7 @@ public static Dictionary ParametersFormat(object instance, strin return formatList; } + private static Dictionary ProcessParametersAfterInvoke(MethodInfo methodInfo, object[] parametersForInvocation, object returnParm) { Dictionary outputParameters = new Dictionary(); @@ -192,7 +218,7 @@ private static Dictionary ProcessParametersAfterInvoke(MethodInf } - internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IDictionary parameters, IGxContext context=null) + internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IDictionary parameters, IGxContext context = null) { var methodParameters = methodInfo.GetParameters(); object[] parametersForInvocation = new object[methodParameters.Length]; @@ -200,14 +226,14 @@ internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IDict foreach (var methodParameter in methodParameters) { object value; - + var gxParameterName = GxParameterName(methodParameter.Name).ToLower(); Type parmType = methodParameter.ParameterType; if (IsByRefParameter(methodParameter)) { parmType = parmType.GetElementType(); } - if (parameters!=null && parameters.TryGetValue(gxParameterName, out value)) + if (parameters != null && parameters.TryGetValue(gxParameterName, out value)) { var convertedValue = ConvertStringToNewType(value, parmType, context); parametersForInvocation[idx] = convertedValue; @@ -221,6 +247,41 @@ internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IDict } return parametersForInvocation; } + + internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IList parameters, IGxContext context = null) + { + var methodParameters = methodInfo.GetParameters(); + object[] parametersForInvocation = new object[methodParameters.Length]; + var idx = 0; + foreach (var methodParameter in methodParameters) + { + Type parmType = methodParameter.ParameterType; + if (IsByRefParameter(methodParameter)) + { + parmType = parmType.GetElementType(); + } + object value = parameters.ElementAt(idx); + if (!value.GetType().Equals(parmType)) + { + //To avoid convertion from string type + if (value.GetType() != typeof(string)) + { + var convertedValue = ConvertStringToNewType(value, parmType, context); + parametersForInvocation[idx] = convertedValue; + } + else + { + throw new ArgumentException("Type not match", methodParameter.Name); + } + } + else + { + parametersForInvocation[idx] = value; + } + idx++; + } + return parametersForInvocation; + } private static Regex attVar = new Regex(@"^AV?\d{1,}", RegexOptions.Compiled); private static string GxParameterName(string methodParameterName) { diff --git a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj b/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj new file mode 100644 index 000000000..c309d4e58 --- /dev/null +++ b/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj @@ -0,0 +1,19 @@ + + + + net462;net6.0 + + + + + + + + + + + + + + + diff --git a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs b/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs new file mode 100644 index 000000000..48ab71b43 --- /dev/null +++ b/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs @@ -0,0 +1,175 @@ +using GeneXus.Application; +using GeneXus.Metadata; +using GeneXus.Utils; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace Genexus.DynamicCall +{ + public class GxDynamicCall + { + private const string defaultMethod = "execute"; + private string _assemblyName; + private Assembly _assembly; + private string _namespace; + private string _externalName; + private GxUserType _properties; + private object _object; + public string ObjectName { get; set; } + public GxUserType Properties + { + get => _properties; + set + { + _properties = Properties; + _assemblyName = (string) _properties.GetType().GetProperty("gxTpr_Assemblyname").GetValue(_properties); + _namespace = (string) _properties.GetType().GetProperty("gxTpr_Namespace").GetValue(_properties); + _externalName = (string)_externalName.GetType().GetProperty("gxTpr_Externalname").GetValue(_properties); + } + } + + public GxDynamicCall() + { + _assemblyName= null; + _assembly= null; + _namespace= null; + _properties= null; + _externalName = null; + _object = null; + } + + private void VerifyDefaultProperties() { + _namespace = string.IsNullOrEmpty(_namespace) ? "GeneXus.Programs" : _namespace; + + if (_assembly is null) + { + if (string.IsNullOrEmpty(_assemblyName)) + { + _assembly = Assembly.GetCallingAssembly(); + } + else + { + try + { + _assembly = Assembly.LoadFrom(_assemblyName); + } + catch + { + throw; + } + } + } + } + + public void Execute(ref IList parameters, out IList errors) + { + System.Diagnostics.Debugger.Launch(); + Create(null, out errors); + if (errors.Count == 0) + { + try + { + IList outParms = ReflectionHelper.CallMethod(_object, defaultMethod, parameters); + parameters = outParms; + } + catch (Exception e) + { + GXUtil.ErrorToMessages("CallMethod Error", e.Message, (GXBaseCollection)errors); + } + } + } + + public void Create( IList constructParms, out IList errors) + { + errors = new GXBaseCollection(); + string objectNameToInvoke; + try + { + VerifyDefaultProperties(); + if (constructParms is null) + { + objectNameToInvoke = ObjectName; + } + else + { + objectNameToInvoke = _externalName; + } + try + { + Type objType = ClassLoader.FindType(objectNameToInvoke, _namespace, objectNameToInvoke.ToLower().Trim(), _assembly); + object[] constructorParameters; + if (constructParms != null && constructParms.Count > 0) + { + constructorParameters = new object[constructParms.Count]; + constructParms.CopyTo(constructorParameters, 0); + } + else + { + constructorParameters = Array.Empty(); + } + _object = Activator.CreateInstance(objType, constructorParameters); + } + catch (Exception e) + { + GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection) errors); + } + } + catch (Exception e) + { + GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection)errors); + } + } + public object Execute(ref IList parameters, GxUserType methodconfiguration , out IList errors) + { + object result; + errors = new GXBaseCollection(); + IList outParms= new List(); +#if NET462_OR_GREATER + GxUserType methodPlatformSubLevel=(GxUserType)methodconfiguration.GetType().GetProperty("gxTpr_Netframework").GetValue(methodconfiguration); +#elif NET5_0_OR_GREATER + GxUserType methodPlatformSubLevel=(GxUserType)methodconfiguration.GetType().GetProperty("gxTpr_Net").GetValue(methodconfiguration); +#endif + string methodName = (string)methodPlatformSubLevel.GetType().GetProperty("gxTpr_Methodname").GetValue(methodconfiguration); + bool isStatic = (bool)methodconfiguration.GetType().GetProperty("gxTpr_Methodisstatic").GetValue(methodconfiguration); + if (!isStatic) + { + if (_object != null) + { + try + { + outParms = ReflectionHelper.CallMethod(_object, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters); + } + catch (Exception e) + { + GXUtil.ErrorToMessages("CallMethod Error", e.Message, (GXBaseCollection)errors); + } + } + else + { + GXUtil.ErrorToMessages("NullInstance Error", "You must invoke create method before execute a non static one", (GXBaseCollection)errors); + } + } + else + { + VerifyDefaultProperties(); + Type objType = ClassLoader.FindType(_externalName, _namespace, _externalName.ToLower().Trim(), _assembly); + outParms = ReflectionHelper.CallMethod(objType, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters, isStatic); + } + if (outParms.Count > parameters.Count) + { + result = outParms[parameters.Count]; + outParms.RemoveAt(parameters.Count); + + } + else + { + result = null; + } + parameters = outParms; + return result; + } + + } +} + From 3913d5e3b82ad4af06dfa71a652725517e1edf56 Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Mon, 28 Mar 2022 12:12:59 -0300 Subject: [PATCH 2/8] Project location change and minor fixes --- .../GXDynamicCall/GXDynamicCall.csproj | 19 +++++++++++++++++++ .../GXDynamicCall/GxDynamicCall.cs | 1 - .../GxClasses/Services/ReflectionHelper.cs | 2 +- .../dotnet/GXDynamicCall/GXDynamicCall.csproj | 19 ------------------- 4 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj rename dotnet/src/{extensions/DynamicCall/dotnet => dotnetcore}/GXDynamicCall/GxDynamicCall.cs (99%) delete mode 100644 dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj b/dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj new file mode 100644 index 000000000..2a9e141f7 --- /dev/null +++ b/dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj @@ -0,0 +1,19 @@ + + + + net462;net6.0 + + + + + + + + + + + + + + + diff --git a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs b/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs similarity index 99% rename from dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs rename to dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs index 48ab71b43..6ca2bc5d1 100644 --- a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GxDynamicCall.cs +++ b/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs @@ -64,7 +64,6 @@ private void VerifyDefaultProperties() { public void Execute(ref IList parameters, out IList errors) { - System.Diagnostics.Debugger.Launch(); Create(null, out errors); if (errors.Count == 0) { diff --git a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs index f9bc09fb7..adb907cd8 100644 --- a/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs +++ b/dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs @@ -271,7 +271,7 @@ internal static object[] ProcessParametersForInvoke(MethodInfo methodInfo, IList } else { - throw new ArgumentException("Type not match", methodParameter.Name); + throw new ArgumentException("Type does not match", methodParameter.Name); } } else diff --git a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj b/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj deleted file mode 100644 index c309d4e58..000000000 --- a/dotnet/src/extensions/DynamicCall/dotnet/GXDynamicCall/GXDynamicCall.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net462;net6.0 - - - - - - - - - - - - - - - From 4418e0ffb64736011f68a4eff7caa2c1e80a2ae6 Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Tue, 19 Apr 2022 11:03:05 -0300 Subject: [PATCH 3/8] Refactor to avoid use Genexus SDT --- .../GXDynamicCall/GxDynCallMethodConf.cs | 27 +++++++++++++++ .../GXDynamicCall/GxDynCallProperties.cs | 28 +++++++++++++++ .../dotnetcore/GXDynamicCall/GxDynamicCall.cs | 34 +++++++------------ 3 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs create mode 100644 dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs b/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs new file mode 100644 index 000000000..f594cc10f --- /dev/null +++ b/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Genexus.DynamicCall +{ + public class GxDynCallMethodConf + { + public bool IsStatic + { + get; set; + } + public string MethodName + { + get; set; + } + + public GxDynCallMethodConf() + { + IsStatic = false; + MethodName = "execute"; + } + + } +} diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs b/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs new file mode 100644 index 000000000..739f2c7d7 --- /dev/null +++ b/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace Genexus.DynamicCall +{ + public class GxDynCallProperties + { + public string ExternalName { + get; + set; + } + public string AssemblyName + { + get; + set; + } + public string NameSpace + { + get; + set; + } + + } +} diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs b/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs index 6ca2bc5d1..4ad4e3dbc 100644 --- a/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs +++ b/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs @@ -14,18 +14,18 @@ public class GxDynamicCall private Assembly _assembly; private string _namespace; private string _externalName; - private GxUserType _properties; + private GxDynCallProperties _properties; private object _object; public string ObjectName { get; set; } - public GxUserType Properties + public GxDynCallProperties Properties { get => _properties; set { _properties = Properties; - _assemblyName = (string) _properties.GetType().GetProperty("gxTpr_Assemblyname").GetValue(_properties); - _namespace = (string) _properties.GetType().GetProperty("gxTpr_Namespace").GetValue(_properties); - _externalName = (string)_externalName.GetType().GetProperty("gxTpr_Externalname").GetValue(_properties); + _assemblyName = Properties.AssemblyName; + _namespace = Properties.NameSpace; + _externalName = Properties.ExternalName; } } @@ -67,15 +67,8 @@ public void Execute(ref IList parameters, out IList Create(null, out errors); if (errors.Count == 0) { - try - { - IList outParms = ReflectionHelper.CallMethod(_object, defaultMethod, parameters); - parameters = outParms; - } - catch (Exception e) - { - GXUtil.ErrorToMessages("CallMethod Error", e.Message, (GXBaseCollection)errors); - } + GxDynCallMethodConf methodConf = new GxDynCallMethodConf(); + Execute(ref parameters, methodConf, out errors); } } @@ -119,18 +112,15 @@ public void Create( IList constructParms, out IList GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection)errors); } } - public object Execute(ref IList parameters, GxUserType methodconfiguration , out IList errors) + public object Execute(ref IList parameters, GxDynCallMethodConf methodconfiguration , out IList errors) { object result; errors = new GXBaseCollection(); IList outParms= new List(); -#if NET462_OR_GREATER - GxUserType methodPlatformSubLevel=(GxUserType)methodconfiguration.GetType().GetProperty("gxTpr_Netframework").GetValue(methodconfiguration); -#elif NET5_0_OR_GREATER - GxUserType methodPlatformSubLevel=(GxUserType)methodconfiguration.GetType().GetProperty("gxTpr_Net").GetValue(methodconfiguration); -#endif - string methodName = (string)methodPlatformSubLevel.GetType().GetProperty("gxTpr_Methodname").GetValue(methodconfiguration); - bool isStatic = (bool)methodconfiguration.GetType().GetProperty("gxTpr_Methodisstatic").GetValue(methodconfiguration); + + string methodName = methodconfiguration.MethodName; + bool isStatic = methodconfiguration.IsStatic; + if (!isStatic) { if (_object != null) From c0916cd2a9b5addfeafb602c3f76b57938ca49b0 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Tue, 26 Apr 2022 13:23:35 -0300 Subject: [PATCH 4/8] Move GXDynamicCall project to dotnetcommon and add it to the general solution. --- dotnet/DotNetStandardClasses.sln | 7 +++++++ .../GXDynamicCall/GXDynamicCall.csproj | 0 .../GXDynamicCall/GxDynCallMethodConf.cs | 0 .../GXDynamicCall/GxDynCallProperties.cs | 0 .../GXDynamicCall/GxDynamicCall.cs | 2 +- 5 files changed, 8 insertions(+), 1 deletion(-) rename dotnet/src/{dotnetcore => dotnetcommon}/GXDynamicCall/GXDynamicCall.csproj (100%) rename dotnet/src/{dotnetcore => dotnetcommon}/GXDynamicCall/GxDynCallMethodConf.cs (100%) rename dotnet/src/{dotnetcore => dotnetcommon}/GXDynamicCall/GxDynCallProperties.cs (100%) rename dotnet/src/{dotnetcore => dotnetcommon}/GXDynamicCall/GxDynamicCall.cs (97%) diff --git a/dotnet/DotNetStandardClasses.sln b/dotnet/DotNetStandardClasses.sln index eeaf8caad..16cb2569f 100644 --- a/dotnet/DotNetStandardClasses.sln +++ b/dotnet/DotNetStandardClasses.sln @@ -188,6 +188,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GxXsl", "src\dotnetcore\GxXsl\GxXsl.csproj", "{30E7E437-F9B0-42B8-9144-A8E8F972B462}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXDynamicCall", "src\dotnetcommon\GXDynamicCall\GXDynamicCall.csproj", "{621AE146-0AF9-4963-90B7-B58BA5D3EBEA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -462,6 +464,10 @@ Global {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Debug|Any CPU.Build.0 = Debug|Any CPU {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Release|Any CPU.ActiveCfg = Release|Any CPU {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Release|Any CPU.Build.0 = Release|Any CPU + {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -552,6 +558,7 @@ Global {B59F76D8-FDB2-4F51-89DB-F15E9BDFF1DC} = {420E8A4A-11D9-42E9-BFB7-4325EA7330B8} {D97E17A4-C945-4BF3-957E-F73142C4C6D0} = {947E032A-C385-4586-96E3-FC7D2767F082} {30E7E437-F9B0-42B8-9144-A8E8F972B462} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3} + {621AE146-0AF9-4963-90B7-B58BA5D3EBEA} = {F1E13DF4-9F50-41A2-9DC3-04B673B21032} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C} diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj b/dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj similarity index 100% rename from dotnet/src/dotnetcore/GXDynamicCall/GXDynamicCall.csproj rename to dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs similarity index 100% rename from dotnet/src/dotnetcore/GXDynamicCall/GxDynCallMethodConf.cs rename to dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs similarity index 100% rename from dotnet/src/dotnetcore/GXDynamicCall/GxDynCallProperties.cs rename to dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs diff --git a/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs similarity index 97% rename from dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs rename to dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs index 4ad4e3dbc..46ffeacdb 100644 --- a/dotnet/src/dotnetcore/GXDynamicCall/GxDynamicCall.cs +++ b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs @@ -136,7 +136,7 @@ public object Execute(ref IList parameters, GxDynCallMethodConf methodco } else { - GXUtil.ErrorToMessages("NullInstance Error", "You must invoke create method before execute a non static one", (GXBaseCollection)errors); + GXUtil.ErrorToMessages("NullInstance Error", "You must invoke create method before executing a non-static one", (GXBaseCollection)errors); } } else From ca8d9d8401cde48f494300535953a9e48eb10d67 Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Fri, 29 Apr 2022 15:37:47 -0300 Subject: [PATCH 5/8] Change GxDynamicCall to GxClasses --- .../GXDynamicCall/GxDynCallMethodConf.cs | 27 ------------- .../GXDynamicCall/GxDynCallProperties.cs | 28 ------------- .../GxClasses.Web/GxClasses.Web.csproj | 1 + .../GxClasses/Helpers}/GxDynamicCall.cs | 40 ++++++++++++++++++- 4 files changed, 40 insertions(+), 56 deletions(-) delete mode 100644 dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs delete mode 100644 dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs rename dotnet/src/{dotnetcommon/GXDynamicCall => dotnetframework/GxClasses/Helpers}/GxDynamicCall.cs (90%) diff --git a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs deleted file mode 100644 index f594cc10f..000000000 --- a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallMethodConf.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Genexus.DynamicCall -{ - public class GxDynCallMethodConf - { - public bool IsStatic - { - get; set; - } - public string MethodName - { - get; set; - } - - public GxDynCallMethodConf() - { - IsStatic = false; - MethodName = "execute"; - } - - } -} diff --git a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs b/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs deleted file mode 100644 index 739f2c7d7..000000000 --- a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynCallProperties.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - -namespace Genexus.DynamicCall -{ - public class GxDynCallProperties - { - public string ExternalName { - get; - set; - } - public string AssemblyName - { - get; - set; - } - public string NameSpace - { - get; - set; - } - - } -} diff --git a/dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj b/dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj index e8479db8c..ff9c157b1 100644 --- a/dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj +++ b/dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj @@ -11,6 +11,7 @@ + diff --git a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs similarity index 90% rename from dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs rename to dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index 46ffeacdb..a1aa0ac02 100644 --- a/dotnet/src/dotnetcommon/GXDynamicCall/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Reflection; -namespace Genexus.DynamicCall +namespace GeneXus.DynamicCall { public class GxDynamicCall { @@ -160,5 +160,43 @@ public object Execute(ref IList parameters, GxDynCallMethodConf methodco } } + public class GxDynCallMethodConf + { + public bool IsStatic + { + get; set; + } + public string MethodName + { + get; set; + } + + public GxDynCallMethodConf() + { + IsStatic = false; + MethodName = "execute"; + } + + } + + public class GxDynCallProperties + { + public string ExternalName + { + get; + set; + } + public string AssemblyName + { + get; + set; + } + public string NameSpace + { + get; + set; + } + + } } From 3fcb438b5be96176da5cbcc5e32b5bbf3a3064c0 Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Tue, 17 May 2022 16:49:41 -0300 Subject: [PATCH 6/8] Fix external call scenario --- .gitignore | 1 + .../GxClasses/Helpers/GxDynamicCall.cs | 23 ++++++------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index dfc726d36..a46d9e4c6 100644 --- a/.gitignore +++ b/.gitignore @@ -361,3 +361,4 @@ build /dotnet/src/dotnetcore/GxDataInitialization/net6.0/GXDataInitialization.deps.json /dotnet/src/dotnetcore/GxNetCoreStartup/net6.0/GxNetCoreStartup.deps.json /dotnet/src/dotnetcore/Reor/net6.0/Reor.deps.json +/dotnet/.editorconfig diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index a1aa0ac02..682e3aa05 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -10,10 +10,7 @@ namespace GeneXus.DynamicCall public class GxDynamicCall { private const string defaultMethod = "execute"; - private string _assemblyName; private Assembly _assembly; - private string _namespace; - private string _externalName; private GxDynCallProperties _properties; private object _object; public string ObjectName { get; set; } @@ -23,28 +20,22 @@ public GxDynCallProperties Properties set { _properties = Properties; - _assemblyName = Properties.AssemblyName; - _namespace = Properties.NameSpace; - _externalName = Properties.ExternalName; } } public GxDynamicCall() { - _assemblyName= null; _assembly= null; - _namespace= null; - _properties= null; - _externalName = null; + _properties = new GxDynCallProperties(); _object = null; } private void VerifyDefaultProperties() { - _namespace = string.IsNullOrEmpty(_namespace) ? "GeneXus.Programs" : _namespace; + _properties.NameSpace = string.IsNullOrEmpty(_properties.NameSpace) ? "GeneXus.Programs" : _properties.NameSpace; if (_assembly is null) { - if (string.IsNullOrEmpty(_assemblyName)) + if (string.IsNullOrEmpty(_properties.AssemblyName)) { _assembly = Assembly.GetCallingAssembly(); } @@ -52,7 +43,7 @@ private void VerifyDefaultProperties() { { try { - _assembly = Assembly.LoadFrom(_assemblyName); + _assembly = Assembly.LoadFrom(_properties.AssemblyName); } catch { @@ -85,11 +76,11 @@ public void Create( IList constructParms, out IList } else { - objectNameToInvoke = _externalName; + objectNameToInvoke = _properties.ExternalName; } try { - Type objType = ClassLoader.FindType(objectNameToInvoke, _namespace, objectNameToInvoke.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(objectNameToInvoke, _properties.NameSpace, objectNameToInvoke.ToLower().Trim(), _assembly); object[] constructorParameters; if (constructParms != null && constructParms.Count > 0) { @@ -142,7 +133,7 @@ public object Execute(ref IList parameters, GxDynCallMethodConf methodco else { VerifyDefaultProperties(); - Type objType = ClassLoader.FindType(_externalName, _namespace, _externalName.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(_properties.ExternalName, _properties.NameSpace, _properties.ExternalName.ToLower().Trim(), _assembly); outParms = ReflectionHelper.CallMethod(objType, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters, isStatic); } if (outParms.Count > parameters.Count) From 85f0b3e025be891dd3f69e167b2fb6bb15a14c75 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Wed, 18 May 2022 18:49:46 -0300 Subject: [PATCH 7/8] Remove unused GXDynamicCall project. --- dotnet/DotNetStandardClasses.sln | 6 ------ .../GXDynamicCall/GXDynamicCall.csproj | 19 ------------------- 2 files changed, 25 deletions(-) delete mode 100644 dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj diff --git a/dotnet/DotNetStandardClasses.sln b/dotnet/DotNetStandardClasses.sln index 13403faa1..a974b74a0 100644 --- a/dotnet/DotNetStandardClasses.sln +++ b/dotnet/DotNetStandardClasses.sln @@ -188,7 +188,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GxXsl", "src\dotnetcore\GxXsl\GxXsl.csproj", "{30E7E437-F9B0-42B8-9144-A8E8F972B462}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXDynamicCall", "src\dotnetcommon\GXDynamicCall\GXDynamicCall.csproj", "{621AE146-0AF9-4963-90B7-B58BA5D3EBEA}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mocking", "mocking", "{5045873B-E7CF-4317-94C1-0EF8623D23FA}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8E5A25F9-2D64-4742-8227-2A3C5816AFEC}" @@ -473,10 +472,6 @@ Global {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Debug|Any CPU.Build.0 = Debug|Any CPU {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Release|Any CPU.ActiveCfg = Release|Any CPU {30E7E437-F9B0-42B8-9144-A8E8F972B462}.Release|Any CPU.Build.0 = Release|Any CPU - {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {621AE146-0AF9-4963-90B7-B58BA5D3EBEA}.Release|Any CPU.Build.0 = Release|Any CPU {8D05D621-3DB3-459F-8665-BEA4574F4EFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8D05D621-3DB3-459F-8665-BEA4574F4EFF}.Debug|Any CPU.Build.0 = Debug|Any CPU {8D05D621-3DB3-459F-8665-BEA4574F4EFF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -575,7 +570,6 @@ Global {B59F76D8-FDB2-4F51-89DB-F15E9BDFF1DC} = {420E8A4A-11D9-42E9-BFB7-4325EA7330B8} {D97E17A4-C945-4BF3-957E-F73142C4C6D0} = {947E032A-C385-4586-96E3-FC7D2767F082} {30E7E437-F9B0-42B8-9144-A8E8F972B462} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3} - {621AE146-0AF9-4963-90B7-B58BA5D3EBEA} = {F1E13DF4-9F50-41A2-9DC3-04B673B21032} {5045873B-E7CF-4317-94C1-0EF8623D23FA} = {C6AFB6A3-FF0B-4970-B1F1-10BCD3D932B2} {8E5A25F9-2D64-4742-8227-2A3C5816AFEC} = {5045873B-E7CF-4317-94C1-0EF8623D23FA} {8D05D621-3DB3-459F-8665-BEA4574F4EFF} = {8E5A25F9-2D64-4742-8227-2A3C5816AFEC} diff --git a/dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj b/dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj deleted file mode 100644 index 2a9e141f7..000000000 --- a/dotnet/src/dotnetcommon/GXDynamicCall/GXDynamicCall.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net462;net6.0 - - - - - - - - - - - - - - - From 82535c148a495238da14c92f9839f51bbf4212aa Mon Sep 17 00:00:00 2001 From: "dalvarellos@genexus.com" Date: Tue, 5 Jul 2022 14:52:30 -0300 Subject: [PATCH 8/8] Initial context for native calls --- 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 682e3aa05..d6af1f832 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -89,7 +89,7 @@ public void Create( IList constructParms, out IList } else { - constructorParameters = Array.Empty(); + constructorParameters = new object[] { new GxContext() }; } _object = Activator.CreateInstance(objType, constructorParameters); }