Emitting entire class from source

T

thomas.greenleaf

Some time ago I wrote a simple reflection.emit example where I emitted
an entire assembly based on source code. Now I forgot exactly how and
all examples online deal only with defining a class through reflection
methods, defining a method and then finally emitting IL for that
specific method.

What I had then would take a string such as "namespace someName{class
someTest{public int test(int a, int b){return a+b;}}}" and then
emitting a class which I could use through reflection.

I would like to do that again, but I have been unable to find examples
of doing so.
 
J

Jon Skeet [C# MVP]

Some time ago I wrote a simple reflection.emit example where I emitted
an entire assembly based on source code. Now I forgot exactly how and
all examples online deal only with defining a class through reflection
methods, defining a method and then finally emitting IL for that
specific method.

What I had then would take a string such as "namespace someName{class
someTest{public int test(int a, int b){return a+b;}}}" and then
emitting a class which I could use through reflection.

I would like to do that again, but I have been unable to find examples
of doing so.

CSharpCodeProvider? That's what I use for similar purposes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top