private InvokeStaticMethod_Internal ( string TypeName, string Method ) : object | ||
TypeName | string | |
Method | string | |
return | object |
internal object InvokeStaticMethod_Internal(string TypeName, string Method, params object[] args)
{
SetError();
Type type = GetTypeFromName(TypeName);
if (type == null)
{
SetError("Type is not loaded. Please make sure you call LoadAssembly first.");
return null;
}
// fix up all parameters
object[] ar;
if (args == null || args.Length == 0)
ar = new object[0];
else
{
ar = new object[args.Length];
for (int i = 0; i < args.Length; i++)
{
ar[i] = FixupParameter(args[i]);
}
}
ErrorMessage = "";
object Result = null;
try
{
Result = type.InvokeMember(Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, type, ar);
}
catch (Exception ex)
{
SetError(ex.GetBaseException(), true);
throw ex.GetBaseException();
}
// Update ComValue parameters to support ByRef Parameters
for (int i = 0; i < ar.Length; i++)
{
if (args[i] is ComValue)
((ComValue)args[i]).Value = FixupReturnValue(ar[i]);
}
return FixupReturnValue(Result);
}
/// <summary> /// Invokes a static method with the passed parameters and sets the Value property /// from the result value. /// </summary> /// <param name="typeName"></param> /// <param name="method"></param> /// <param name="parms"></param> public void SetValueFromInvokeStaticMethod(string typeName, string method, ComArray parms) { wwDotNetBridge bridge = new wwDotNetBridge(); var list = new List<object>(); if (parms.Instance != null) foreach (object item in parms.Instance as IEnumerable) list.Add(item); Value = bridge.InvokeStaticMethod_Internal(typeName, method, list.ToArray()); }