Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where would you use C# Runtime Compilation?

I happened upon a brief discussion recently on another site about C# runtime compilation recently while searching for something else and thought the idea was interesting. Have you ever used this? I'm trying to determine how/when one might use this and what problem it solves. I'd be very interested in hearing how you've used it or in what context it makes sense.

Thanks much.

like image 591
itsmatt Avatar asked Sep 27 '08 16:09

itsmatt


3 Answers

Typically, I see this used in cases where you are currently using Reflection and need to optimize for performance.

For example, instead of using reflection to call method X, you generate a Dynamic Method at runtime to do this for you.

like image 57
therealhoff Avatar answered Nov 16 '22 15:11

therealhoff


I've seen this (runtime compilation / use of System.Reflection.Emit classes) in generating dynamic proxies ( Code project sample ) or other means of optimizing reflection calls (time-wise).

like image 3
Andrei Rînea Avatar answered Nov 16 '22 15:11

Andrei Rînea


You can use this to add scripting support to your application. For examples look here or here.

It is quite easily possible to publish parts of your internal object framework to the scripting part, so you could with relative ease add something to your application that has the same effect as for example VBA for Office.

like image 5
TToni Avatar answered Nov 16 '22 14:11

TToni