Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing C# source code

Tags:

c#

codedom

I'm trying to parse a simple.cs source 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 an implemenation for parsing C# code? Or am I just using this class the wrong way?

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

like image 802
Boris Avatar asked Sep 29 '14 05:09

Boris


1 Answers

Yes, that's true, the CodeDomProvider is for emitting source code, not reading it. Various companies have their own parsers and recently Microsoft started project Roslyn that provides such features.

like image 96
nvoigt Avatar answered Oct 04 '22 21:10

nvoigt