如何获得MethodInfo
对于 Array.IndexOf<string>(string[], string)
?
我尝试使用此代码,但不起作用。
typeof(Array).GetMethod("IndexOf",
BindingFlags.Public | BindingFlags.Static, null,
new Type[] { typeof(string[]), typeof(string) }, null);
最佳答案
使用 BindingFlags.Public | BindingFlags.Static
编辑:
下面的评论是正确的,问题是 IndexOf
方法是通用的——只有一个 Array.IndexOf<T>(T[], T)
.为了得到那个,这对我有用:
var indexOfGeneric = typeof(Array).GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(m => m.Name == "IndexOf"
&& m.GetParameters().Length == 2
&& m.IsGenericMethod );
关于c# - 如何获取 Array.IndexOf<string>(string[], string) 方法信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9132122/