Skip to content

Commit f77b6aa

Browse files
author
dalvarellos
committed
Use collection for properties and pass context to called object
1 parent 9b6e49b commit f77b6aa

File tree

1 file changed

+31
-55
lines changed

1 file changed

+31
-55
lines changed
Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
using GeneXus.Application;
2-
using GeneXus.Metadata;
3-
using GeneXus.Utils;
41
using System;
52
using System.Collections.Generic;
63
using System.Reflection;
4+
using GeneXus.Application;
5+
using GeneXus.Metadata;
6+
using GeneXus.Utils;
77

88
namespace GeneXus.DynamicCall
99
{
10-
public class GxDynamicCall
11-
{
10+
public class GxDynamicCall
11+
{
1212
private const string defaultMethod = "execute";
1313
private Assembly _assembly;
14-
private GxDynCallProperties _properties;
14+
private readonly IGxContext _context;
15+
private GXProperties _properties;
1516
private object _object;
16-
public string ObjectName { get; set; }
17-
public GxDynCallProperties Properties
17+
public string ExternalName { get; set; }
18+
public GXProperties Properties
1819
{
1920
get => _properties;
2021
set
@@ -23,27 +24,28 @@ public GxDynCallProperties Properties
2324
}
2425
}
2526

26-
public GxDynamicCall()
27+
public GxDynamicCall(IGxContext context)
2728
{
28-
_assembly= null;
29-
_properties = new GxDynCallProperties();
29+
_context = context;
30+
_assembly = null;
31+
_properties = new GXProperties();
3032
_object = null;
3133
}
3234

33-
private void VerifyDefaultProperties() {
34-
_properties.NameSpace = string.IsNullOrEmpty(_properties.NameSpace) ? "GeneXus.Programs" : _properties.NameSpace;
35-
35+
private void VerifyDefaultProperties()
36+
{
37+
3638
if (_assembly is null)
3739
{
38-
if (string.IsNullOrEmpty(_properties.AssemblyName))
40+
if (string.IsNullOrEmpty(_properties.Get("AssemblyName")))
3941
{
4042
_assembly = Assembly.GetCallingAssembly();
4143
}
4244
else
4345
{
4446
try
4547
{
46-
_assembly = Assembly.LoadFrom(_properties.AssemblyName);
48+
_assembly = Assembly.LoadFrom(_properties.Get("AssemblyName"));
4749
}
4850
catch
4951
{
@@ -63,24 +65,19 @@ public void Execute(ref IList<object> parameters, out IList<SdtMessages_Message>
6365
}
6466
}
6567

66-
public void Create( IList<object> constructParms, out IList<SdtMessages_Message> errors)
68+
public void Create(IList<object> constructParms, out IList<SdtMessages_Message> errors)
6769
{
6870
errors = new GXBaseCollection<SdtMessages_Message>();
6971
string objectNameToInvoke;
7072
try
7173
{
7274
VerifyDefaultProperties();
73-
if (constructParms is null)
74-
{
75-
objectNameToInvoke = ObjectName;
76-
}
77-
else
78-
{
79-
objectNameToInvoke = _properties.ExternalName;
80-
}
75+
76+
objectNameToInvoke = ExternalName;
77+
8178
try
8279
{
83-
Type objType = ClassLoader.FindType(objectNameToInvoke, _properties.NameSpace, objectNameToInvoke.ToLower().Trim(), _assembly);
80+
Type objType = ClassLoader.FindType(objectNameToInvoke, objectNameToInvoke.ToLower().Trim(), _assembly);
8481
object[] constructorParameters;
8582
if (constructParms != null && constructParms.Count > 0)
8683
{
@@ -89,27 +86,27 @@ public void Create( IList<object> constructParms, out IList<SdtMessages_Message>
8986
}
9087
else
9188
{
92-
constructorParameters = new object[] { new GxContext() };
89+
constructorParameters = new object[] { _context };
9390
}
9491
_object = Activator.CreateInstance(objType, constructorParameters);
9592
}
9693
catch (Exception e)
9794
{
98-
GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection<SdtMessages_Message>) errors);
95+
GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection<SdtMessages_Message>)errors);
9996
}
10097
}
10198
catch (Exception e)
10299
{
103100
GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection<SdtMessages_Message>)errors);
104101
}
105102
}
106-
public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodconfiguration , out IList<SdtMessages_Message> errors)
103+
public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodconfiguration, out IList<SdtMessages_Message> errors)
107104
{
108105
object result;
109106
errors = new GXBaseCollection<SdtMessages_Message>();
110-
IList<object> outParms= new List<object>();
107+
IList<object> outParms = new List<object>();
111108

112-
string methodName = methodconfiguration.MethodName;
109+
string methodName = methodconfiguration.MethodName;
113110
bool isStatic = methodconfiguration.IsStatic;
114111

115112
if (!isStatic)
@@ -118,7 +115,7 @@ public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodco
118115
{
119116
try
120117
{
121-
outParms = ReflectionHelper.CallMethod(_object, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters);
118+
outParms = ReflectionHelper.CallMethod(_object, string.IsNullOrEmpty(methodName) ? defaultMethod : methodName, parameters);
122119
}
123120
catch (Exception e)
124121
{
@@ -133,7 +130,7 @@ public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodco
133130
else
134131
{
135132
VerifyDefaultProperties();
136-
Type objType = ClassLoader.FindType(_properties.ExternalName, _properties.NameSpace, _properties.ExternalName.ToLower().Trim(), _assembly);
133+
Type objType = ClassLoader.FindType(ExternalName, ExternalName.ToLower().Trim(), _assembly);
137134
outParms = ReflectionHelper.CallMethod(objType, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters, isStatic);
138135
}
139136
if (outParms.Count > parameters.Count)
@@ -169,25 +166,4 @@ public GxDynCallMethodConf()
169166
}
170167

171168
}
172-
173-
public class GxDynCallProperties
174-
{
175-
public string ExternalName
176-
{
177-
get;
178-
set;
179-
}
180-
public string AssemblyName
181-
{
182-
get;
183-
set;
184-
}
185-
public string NameSpace
186-
{
187-
get;
188-
set;
189-
}
190-
191-
}
192-
}
193-
169+
}

0 commit comments

Comments
 (0)