Get all code statements in specific code element with EnvDte

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:06:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!