Parser for C# [closed]

Which parsers are available for parsing C# code?

I'm looking for a C# parser that can be used in C# and give me access to line and file informations about each artefact of the analysed code.


Works on source code:

  • CSParser: From C# 1.0 to 2.0, open-source
  • Metaspec C# Parser: From C# 1.0 to 3.0, commercial product (about 5000$)
  • #recognize!: From C# 1.0 to 3.0, commercial product (about 900€) (answer by SharpRecognize)
  • SharpDevelop Parser (answer by Akselsson)
  • NRefactory: From C# 1.0 to 4.0 (+async), open-source, parser used in SharpDevelop. Includes semantic analysis.
  • C# Parser and CodeDOM: A complete C# 4.0 Parser, already support the C# 5.0 async feature. Commercial product (49$ to 299$) (answer by Ken Beckett)
  • Microsoft Roslyn CTP: Compiler as a service.

Works on assembly:

  • System.Reflection
  • Microsoft Common Compiler Infrastructure: From C# 1.0 to 3.0, Microsoft Public License. Used by Fxcop and Spec#
  • Mono.Cecil: From C# 1.0 to 3.0, open-source

The problem with assembly "parsing" is that we have less informations about line and file (the informations is based on .pdb file, and Pdb contains lines informations only for methods)

I personnaly recommend Mono.Cecil and NRefactory.


Mono (open source) includes C# compiler (and of course parser)