Possible Duplicate:
C# code generator
For example, what I would like to do is something like:
Sourcefile sf = new SourceFile("Dog.cs");
sf.add(new Class("Dog"));
sf.Write();
and get some text file like:
public class Dog()
{
}
I can do this myself, but wanted to check around to see if it already existed.
That's what System.Reflection.Emit
namespace is for.
Start reading @ MSDN.
Here's a Hello World example.
You might want to look into System.CodeDom
as well.
Here's an example on MSDN.
Use the one that better suits your code generation needs.
PS. If you want to generate code at design time you might want to use T4 templates.
精彩评论