Parsing C # Source Code

I am trying to parse the source simple.cs file using the following code:

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); var compileUnit = provider.Parse(File.OpenText(filename)); 

This gives me a NotImplementedException:

"This CodeDomProvider does not support this method"

Is it true that .NET does not provide the implementation of parsing code in C #? Or am I just using this class incorrectly?

Edit: the reason for this is because I want to play around with some methods for static code analysis. Compiling or executing code is not required for my research.

+5
source share
1 answer

Yes, it is true, CodeDomProvider designed to emit source code, not read. Different companies have their own parsers, and Microsoft recently launched the Roslyn project, which provides such features.

+8
source

Source: https://habr.com/ru/post/1203587/


All Articles