Dynamically calling a dll and method with arguments

怎甘沉沦 提交于 2019-12-04 06:23:36

I found two issues with your code:

  1. You are not looping over all parameters. You should remove -1 from the for loop.
  2. When you are creating your converter, you call the GetType() method. This returns the Type of the ParameterInfo object, not the Type of the parameter. Use the property ParameterType instead.

All in all, change the first lines in the for loop to this:

for (int i = 0; i < parameters.Length; i++)
{
   var converter = TypeDescriptor.GetConverter(parameters[i].ParameterType);

Once you have done these corrections, I believe your code should run as intended. At least it did for me when I tested a simple void Hello(int x, string y) method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!