Get all code statements in specific code element w

2019-07-24 03:19发布

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条回答
地球回转人心会变
2楼-- · 2019-07-24 03:47

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

查看更多
登录 后发表回答