Possible Duplicate:
Parser for C#
Say if I had a simple class such as inside a textbox control in a winforms application:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public void DoSomething(string x)
{
return "Hello " + x;
}
}
Is there an easy way I can parse the following items from it:
- Class Name
- Properties
- Any public methods
Any ideas/suggestions appreciated.
You can use Reflection for that:
UPDATE First step for you is compiling your class
Next you should verify if your text is a valid c# code. Actually your code is not valid – method DoSomething marked as void, but it returns a string.
So far so good. Now get types from your compiled in-memory assembly:
In your case there will be only
Persontype. But anyway – now you can use Reflection to get properties, methods, etc from these types: