Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have a requirement where i need to fetch all the method names from the .cs file of a given file path(it is the path of the .cs file in other application).
Posted

1) Read the file.
2) Use regular expression to determine the method signature. If it matches, get the method name.
 
Share this answer
 
Comments
sainath437 21-Jul-10 8:05am    
can you help me out some more with the regex expression or else provide some reference links..
Ankur\m/ 21-Jul-10 8:20am    
Creating the regex is the most important and complex part of your requirement. I won't write it for you but surely would try to help you writing it.
First of all get a copy of Expresso from http://www.codeproject.com/kb/dotnet/expresso.aspx
The next thing would be to determine different combinations of a method signature. So you need to get all instances of public/protected/private, return type, virtual/override etc, MethodName, (, optional parameters, ).

I would say start trying. If you have issues get back. Me and others will try to help. :thumbsup:

[Edit]I guess custom parsers should be available. Let me check. [/Edit]
Ankur\m/ 21-Jul-10 8:38am    
Hey I got a couple of posts talking about the same thing. Go through it. It talks about regex method and custom parsers and some VS add-ins. It should help you. Here are the links:
http://stackoverflow.com/questions/261741/get-a-methods-contents-from-a-cs-file
http://stackoverflow.com/questions/906483/how-to-get-classes-and-methods-from-a-cs-file-using-reflections-in-c
If you have access to the class you can do it by reflection,

typeOf(MyClass).GetMethods()


This code is not tested and not exactly same. You can find a similar method with intellisense.
 
Share this answer
 
Comments
sainath437 21-Jul-10 8:02am    
Thanx Arun for ur replay.
i have tried this , but my problem is that i need the method names from a .cs file which is in another application . i will give the path of the .cs file and i require it show the method names.
your answer works if the .cs file in the same application .
Hi
You can use dotnet Reflection Concept for this, here is the step by step HELP
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900