471,350 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

How to parse the names of methods & variables in a cs file

I would like to make a list of all the names of methods and variables
in a cs file. I need to open up a file, create the list of all methods
and properties, and variables, contained in that file, and close the
file.

Is there any class that will help me doing that?

Cheers,
Simone

Jan 21 '06 #1
5 1261
Hello Simone,

How would u like to do it? Statically? Use CodeSmith tool for this case

SM> I would like to make a list of all the names of methods and
SM> variables in a cs file. I need to open up a file, create the list of
SM> all methods and properties, and variables, contained in that file,
SM> and close the file.
SM>
SM> Is there any class that will help me doing that?
SM>
SM> Cheers,
SM> Simone
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jan 21 '06 #2
Simone M <si************@hotmail.com> wrote:
I would like to make a list of all the names of methods and variables
in a cs file. I need to open up a file, create the list of all methods
and properties, and variables, contained in that file, and close the
file.

Is there any class that will help me doing that?


Do you definitely need to do it on the C# file itself, rather than the
assembly which is produced? It's much easier to do with reflection on
the generated code than it is to effectively do a lot of the parsing
work that the C# compiler does.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 21 '06 #3
Jon,
Thanks for the tip. I thought there would be a class available to do it
directly on the cs file.
But I will give Reflection a try.
Cheers!
Simone

Jan 21 '06 #4
Michael,
Thanks for the tip. Will take a look at CodeSmith.
Simone

Jan 21 '06 #5
As well, you could look into FxCop, which validates .NET code by
examining the compiled assemblies.

FxCop allows you to add custom rules, so if you're doing this in order
to check a naming convention (for example), you could get that "for
free" by reading up on how to write custom rules in FxCop and
leveraging off that framework. They've done all the heavy lifting for
you... all you have to supply are the additional rules to check.

Of course, if you want the names for some other purpose, that may not
work for you.

Jan 21 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jonathan Epstein | last post: by
6 posts views Thread by Mayer | last post: by
4 posts views Thread by arak123 | last post: by
7 posts views Thread by amfr | last post: by
16 posts views Thread by per9000 | last post: by
4 posts views Thread by Victor Lagerkvist | last post: by
1 post views Thread by maconbot | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.