Extracting property names from a c# source file
Posted
by Pete
on Stack Overflow
See other posts from Stack Overflow
or by Pete
Published on 2010-06-10T13:36:43Z
Indexed on
2010/06/10
15:03 UTC
Read the original article
Hit count: 237
c#
|csharpcodeprovider
I want to parse a c# file. The only thing I want is to determine if it contains a property with a specific name; just a simple true/false response. Or rather, since I'd checking for more than one property in each run, extracting a list of property names could be helpful
I thought that I could create an elegant solution using the CodeDomProvider
functionality (f# example):
use reader = new StreamReader(existingFile)
let codeProvider = new CSharpCodeProvider()
let codeUnit = codeProvider.Parse(reader)
Unfortunately, the Parse
function is not implemented for the CSharpCodeProvider
. Is there a way to get a CodeCompileUnit
from a source file? Or is there another elegant way? (I had hoped to avoid regular expressions on this)?
© Stack Overflow or respective owner