我正在使用反射来获取 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 告诉我这是因为第二个参数是一个输出参数。
有人知道我在这里做错了什么吗?
最佳答案
试试这个
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/