使用roslyn api获取类型的所有扩展方法

时间:2016-11-21 19:05:59

标签: c# methods reflection roslyn

我想获取类型的所有扩展方法。例如,对于类型string,如果我使用semanticmodel方法lookupsymbols。

var sourceText = @"string a = "";
a."
var tree= CSharpSyntaxTree.ParseText(sourceTextx...);
....
var members = semanticModel.LookupSymbols(source.IndexOf("a."), someType, includeReducedExtensionMethods: true);
//this return all members with extension methods for type string someExtMethod(this string text)....


//I want get all extension with methods where first param might be one of them 
var interfaces = someType.AllInerfaces;
//for example IEnumerable<out T>, methods like: Select, Where, Aggregate...

1 个答案:

答案 0 :(得分:1)

调用SemanticModel.LookupSymbols以从容器中获取所有有效符号。

这是how IntelliSense works