先看这个代码:
Reflection中对于out类型的获取using System;
Reflection中对于out类型的获取
Reflection中对于out类型的获取
namespace AppTest

我的目的,是通过反射,得到SetValue带有两个参数的这个MethodInfo。一般的,我们会调用包含GetMethod中第5个或者第6个重载的方法,即,包含ParameterModifier的那个方法。但是不知道为什么,返回的MethodInfo总是null。后来google了一下GetMethod ParameterModifier,到.net247上找到了一个答案。代码修改为这样,可以了:
Reflection中对于out类型的获取            Assembly asm = Assembly.LoadFrom(@"D:\Programs\vs.net\SerialGen\Test\bin\Debug\test.dll");
Reflection中对于out类型的获取            Type t 
= asm.GetType("AppTest.AppTest1");
Reflection中对于out类型的获取            
Reflection中对于out类型的获取            
// 这段定义是下面第一个GetMethod使用的
Reflection中对于out类型的获取
            ParameterModifier[] pm = new ParameterModifier[2];
Reflection中对于out类型的获取            pm[
0= new ParameterModifier(1);
Reflection中对于out类型的获取            pm[
0][0= false;
Reflection中对于out类型的获取            pm[
1= new ParameterModifier(1);
Reflection中对于out类型的获取            pm[
1][0= true;
Reflection中对于out类型的获取
Reflection中对于out类型的获取            
// 这行,返回的mi是null
);

第二个GetMethod中的TypeList,直接写成了System.String&就可以了。
第一种方式,为什么不可以?对于上面的pm的赋值,也这样写过:
Reflection中对于out类型的获取            ParameterModifier[] pm = new ParameterModifier[1];
Reflection中对于out类型的获取            pm[
0= new ParameterModifier(2);
Reflection中对于out类型的获取            pm[
0][0= false;
Reflection中对于out类型的获取            pm[
0][1= true;

不过,也不正确。Reflection中对于out类型的获取,不知道,这玩艺到底怎么用啊?Reflection中对于out类型的获取

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-07-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
相关资源
相似解决方案