【发布时间】:2015-03-06 11:16:44
【问题描述】:
我知道我可以使用question 中的技术来获取我的方法。
例如
MethodInfo firstMethod = typeof(Enumerable)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(m => m.Name == "FirstOrDefault" && m.GetParameters().Length == 1)
不过我想缩短这个过程。
我在找Enumerable.FirstOrDefault Method (IEnumerable)
我都试过了
// I'm just using string just as an example.
var enumerableType = typeof(IEnumerable<>).MakeGenericType(typeof(string));
MethodInfo firstMethod = typeof(Enumerable)
.GetMethod("FirstOrDefault", new Type[] { enumerableType });
和
MethodInfo firstMethod = typeof(Enumerable)
.GetMethod("FirstOrDefault", Type.EmptyTypes);
但两者都返回null。
正确的方法是什么?
【问题讨论】:
标签: c# reflection