我正在使用反射来获取TryParse方法信息(赞成第一人猜测原因;)。

如果我打电话给:

typeof(Int32).GetMethod("Parse",
  BindingFlags.Static | BindingFlags.Public,
  null,
  new Type[] { typeof(string) },
  null);

我得到了一个方法,但是稍微扩展了一下:
typeof(Int32).GetMethod("TryParse",
  BindingFlags.Static | BindingFlags.Public,
  null,
  new Type[] { typeof(string), typeof(Int32) },
  null);

我什么也没回来。我的Spidersense告诉我这是因为第二个参数是out参数。

有人知道我在这里做错了吗?

最佳答案

试试这个

typeof(Int32).GetMethod("TryParse",
  BindingFlags.Static | BindingFlags.Public,
  null,
  new Type[] { typeof(string), typeof(Int32).MakeByRefType() },
  null);

关于c# - 为Type.GetMethod指定参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4515642/

10-11 22:41
查看更多