I recommend at least watching the LINQOver # project, hosted on codeproject.com.
URL: http://www.codeplex.com/LinqOverCSharp
There are some (minor?) Known issues, and it has not been updated since January 2008 (which can be a pretty big problem), but the source code for the (fast and 100% .Net) C # 3.0 parser exists for adoption.
My favorite things about this parser are:
It can load the Visual Studio project file (csproj) pretty much out of the box and parse the entire shebang (including assembly references).
You can query, list, filter, etc. the analyzed object model (tree) using LINQ. Which makes it almost trivial to move up and down and around what you are parsing.
Here's an example LINQ query to find a variable or parameter in a method, where the variable name = VariableName:
variable = (from v in method.Variables where string.Compare(v.Name, VariableName, false) == 0 select v as LanguageElement).Union( from p in method.FormalParameters where string.Compare(p.Name, VariableName, false) == 0 select p as LanguageElement).FirstOrDefault();
Bob black
source share