【发布时间】:2017-03-26 22:12:29
【问题描述】:
如何通过 c# 反射获取“字符串”类型的所有方法,以及“聚合”、“选择”等所有扩展方法?我知道该类型最实现接口 IEnumerable,但是 Enumerable 类中的所有这些扩展方法都具有第一个泛型参数 TSource.Ok... 代码:
var type = typeof(string).GetMethods(); //i get all methods string type
//I want get for this type all extensions methods like "Select" "Where"
//so i get all interfaces
type.GetInterfaces();
//ICompareble
//ICloneable
//...
//IEnumearable, but all this interfaces don't have extensions methods
//They locate in Enumerable class
//how i can use string type go to Enumerable class and get all this methods
//Somthigs like this
typeof(Enumerable).GetMethods(); //i want get all this methods but using type "string"
//Aggregate
//Select
//where
【问题讨论】:
-
我认为您很容易为您的问题发布可重现的代码,以便我们可以在我们的机器上对其进行测试..
-
这个 [link]stackoverflow.com/questions/299515/… 方法不起作用,因为他使用第一个参数 typeof(string),在我的版本中,这个方法有第一个参数通用 TSource。
标签: c# string visual-studio reflection typeof