I am working on a project where there is a need to generate c# code in real time. The resulting code should be used as a new library in other projects. To explain clearly, Please look at PaintCode, a program like this is in my mind. which technologies do you think they have applied to produce code generation? I know we can use System.Reflection to generate types as mentioned here. But How can I grab user actions and generate method bodies dynamically. Does exist any standard solution to do this in .NET Or I have to make everything myself from scratch?
Senario
For example suppose we have implemented an environment that user can insert operations (blue square) and objects (orange circles) to it with drag and drop. In the following picture user wants to define an Add operation for two input objects a and b.
Suppose a and b are objects of a predefined type "Box" and "Add" is a simple + operator. When user drags a line from A.length and B.length to the + square it means
A.length + B.length
. So when the user does this I need a way to store it and create a c# code like the following code block in real time. (It's an example for clarity please don't waste your time to analyze it):
using blabla.Box;
public static Box operator+ (Box a, Box b)
{
Box box = new Box();
box.length = b.length + c.length;
box.height = b.height + c.height;
return box;
}
All of this magic should happen real time and automatically.
The Question
If I save all user's activity in a list. How can I convert this object to a c# code? What should I do to find the dependencies and required namespaces in addition to my own. What can CodeDOM do for me? Do I need to build the codes line by line and manually? Or does exist any library or something like that which help me in this regard? Thanks for any suggestion.