简体   繁体   English

如何使用带有反射的调用来获取ref参数

[英]How can take ref parameter using Invoke with Reflection

How can take ref parameter(OutputData) using Invoke with Reflection. 如何使用带有反射的Invoke来获取ref参数(OutputData)。 objectValues is an object array that take an parameters is sending parameter to "FM_DEC_ENC" Method.This method contains 8 parameter. objectValues是一个带参数的对象数组,该参数将参数发送到“ FM_DEC_ENC”方法。此方法包含8个参数。 One of them is outputData re parameter 其中之一是outputData re参数

 mInfo.Invoke("FM_DEC_ENC", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                 null, objectValues,null)

public Int32 FM_DEC_ENC(String AdapterID, String SlotID, String InputData, 
        String DecKeyName, String EncKeyName, HsmCommConstants.ENCRIPTION DecEcbOrCbc,
        HsmCommConstants.ENCRIPTION EncEcbOrCbc, ref String OutputData)

You are already doing it correctly by keeping a reference to the parameter array. 通过保留对参数数组的引用,您已经正确地做到了。 When the method returns, the result will be in objectValues[7] . 方法返回时,结果将在objectValues[7]

Note that this won't work if FM_DEC_ENC is a native method that expects a modifiable buffer as OutputData (because System.String cannot be modified). 请注意,如果FM_DEC_ENC是本机方法希望将可修改的缓冲区用作OutputData ,则此方法将无效(因为System.String无法修改)。 In this case, you can also specify StringBuilder as parameter type . 在这种情况下, 您还可以将StringBuilder指定为参数type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM