问题
By code statement i mean smallest standalone element of code. Is there an interface to get code statements inside a EnvDTE.CodeFunction body in a structured form.
There are ways that can retrieve body of EnvDTE.CodeFunction as plain text, and if i want to process method calls etc. i should use Regex which i think is not a general solution. For example both of these statements are same:
var value = @"the "" is qoutation mark"; var value = "the \" is qoutation mark";
but it is a little hard to parse them with regex, and a more straightforward way should be existed with EnvDTE I think!
回答1:
The file code model (EnvDTE.FileCodeModel) doesn't support getting statements inside a method. For VS 2015 and higher you can use the .NET Compiler Platform (formerly "Roslyn") that is the C# / VB.NET parser, compiler, etc. exposed to extensions of Visual Studio. See: .NET Compiler Platform
来源:https://stackoverflow.com/questions/31473588/get-all-code-statements-in-specific-code-element-with-envdte