views:

234

answers:

2

I can get at the method body easily enough using reflection

Type type = assembly.GetType("Lorem.Ipsum.Dolor.Sit");
MethodInfo methodInfo = type.GetMethod("Amet");
MethodBody methodBody = methodInfo.GetMethodBody();

How can I programatically change the method body and save my changes back to disk?

+1  A: 

AFAIK, you can't.

With reflection you modified an in-memory object which was produced from a binary loaded and optimized by the CLR at runtime.

EDIT

This question has some more information on this.

http://stackoverflow.com/questions/123540/modifying-existing-net-assemblies

kervin
That link is very helpful and very similar to what I'm trying to accomplish. Thank you.
Jeffrey LeCours
+1  A: 

you can't do it without third-party libs. take a look at: http://www.mono-project.com/Cecil

Andrey