That's all, I have a method that is currently used to call the DLL type of the return type bool, this works fine. This method
public static bool InvokeDLL(string strDllName, string strNameSpace,
string strClassName, string strMethodName,
ref object[] parameters,
ref string strInformation,
bool bWarnings = false)
{
try
{
if (!File.Exists(Path.GetFullPath(strDllName)))
{
strInformation = String.Format("Cannot locate file '{0}'!",
Path.GetFullPath(strDllName));
return false;
}
else
{
Assembly DLL = Assembly.LoadFrom(Path.GetFullPath(strDllName));
Type classType = DLL.GetType(String.Format("{0}.{1}",
strNameSpace, strClassName));
if (classType != null)
{
object classInstance = Activator.CreateInstance(classType);
MethodInfo methodInfo = classType.GetMethod(strMethodName);
if (methodInfo != null)
{
object result = null;
result = methodInfo.Invoke(classInstance, new object[] { parameters });
return Convert.ToBoolean(result);
}
}
strInformation = String.Format("Could not invoke the requested DLL '{0}'! " +
"Please insure that you have specified the namespace, class name " +
"method and respective parameters correctly!",
Path.GetFullPath(strDllName));
return false;
}
}
catch (Exception eX)
{
strInformation = String.Format("DLL Error: {0}!", eX.Message);
if (bWarnings)
Utils.ErrMsg(eX.Message);
return false;
}
}
Now I want to extend this method to get return values ββfrom DLLs of any type. I planned to do this with the help of generics, but immediately went to unknown territory. How to return T when it is unknown at compile time, I looked at the thoughts, but I'm not sure how it will be used in this case. Make the first check in the code above.
public static T InvokeDLL<T>(string strDllName, string strNameSpace,
string strClassName, string strMethodName,
ref object[] parameters, ref string strInformation,
bool bWarnings = false)
{
try
{
if (!File.Exists(Path.GetFullPath(strDllName)))
{
strInformation = String.Format("Cannot locate file '{0}'!",
Path.GetFullPath(strDllName));
return "WHAT/HOW??";
...
How can I achieve what I want, or am I just overloading the method?
Many thanks for your help.