Hi
I'm currently converting an application from Java to C#, and in this
application I need to read a C# source file, extract some information
and then write a modified version of the original source file. I need
information such as method names, parameters and return statements.
For example, given the method declaration:
public ArrayList MyFunction(int param1, bool param2)
I need both the return type, method name, parameter names and
parameter types.
The original application parses the source code file manually, line by
line, and doing things like splitting the line on commas and then
iterating through the tokens. But the extended syntax of C# is making
this a bit more tricky (e.g. 2d arrays like [ , ]). Another
complicating factor is keywords inside strings and comment. But then I
thought about using reflection. If I have understood correctly, I can
extract method names and parameter types from a compiled application.
But what about parameter names? Another problem, the method is a
recursive one, including a call like MyFunction(x, y) somewhere in the
method. I also need to extract the parameter names (x and y) in this
call.
Can reflection be to any help here, or do I need to continue parse
manually? And is there any other functions in the .NET framework that
can be helpful?