通过反射将ref参数数组传递给C#DLL

通过反射将ref参数数组传递给C#DLL,c#,reflection,dll,pass-by-reference,C#,Reflection,Dll,Pass By Reference,总之,我有很多C#DLL,我想在运行时使用System.Reflection从我的应用程序调用它们。我使用的核心代码类似于 DLL = Assembly.LoadFrom(Path.GetFullPath(strDllName)); classType = DLL.GetType(String.Format("{0}.{0}", strNameSpace, strClassName)); if (classType != null) { classInstance = Activator

总之,我有很多C#DLL,我想在运行时使用
System.Reflection
从我的应用程序调用它们。我使用的核心代码类似于

DLL = Assembly.LoadFrom(Path.GetFullPath(strDllName));
classType = DLL.GetType(String.Format("{0}.{0}", strNameSpace, strClassName));
if (classType != null)
{
    classInstance = Activator.CreateInstance(classType);
    MethodInfo methodInfo = classType.GetMethod(strMethodName);
    if (methodInfo != null)
    {
        object result = null;
        result = methodInfo.Invoke(classInstance, parameters);
        return Convert.ToBoolean(result);
    }
}
我想知道如何将参数数组作为
ref
传递给DLL,以便从DLL中提取信息。我想要的(但当然不会编译)的清晰描述是


如何实现这一点?

ref
参数的更改反映在传递到
MethodInfo.Invoke
的数组中。您只需使用:

object[] parameters = ...;
result = methodInfo.Invoke(classInstance, parameters);
// Now examine parameters...
请注意,如果所讨论的参数是一个参数数组(根据标题),则需要将其包装到另一个级别的数组中:

object[] parameters = { new object[] { "first", "second" } };
就CLR而言,它只是一个参数


如果这没有帮助,请给出一个简短但完整的示例-您不需要使用单独的DLL来演示,只需一个带有
Main
方法和反射调用的方法的控制台应用程序就可以了。

可能会有帮助:非常感谢Jon。我以前在做
result=methodInfo.Invoke(classInst,新对象[]{dllParams})object[] parameters = { new object[] { "first", "second" } };