Tech Off Post

Single Post Permalink

View Thread: Reflection Emit
  • User profile image

    If you mean a business reason to use dynamic compilation in general, we definitely had one.

    In a large pricing application, users had the need to write formulas to generate prices based on certain base prices, prices of other related products, and a set of inbuilt functions reflecting different pricing strategies.

    We did this using CodeDOM, and created a C# class based on what the users entered for each formula, one function per formula. The syntax they used was a slightly modified C# syntax, which we knocked into shape to get it to compile. This was much much quicker than interpreting and parsing the formulas ourselves. The prices of 100s of thousands of products were then calculated based on these formulas, so it made a lot of sense to have them compiled.

    But if you mean specifically a reason for creating a class based on IL opcodes at runtime, I'm not sure. If the users had wanted some totally new expression syntax (like APL maybe) which was unlike any language supported by CodeDOM, maybe it would have made sense to have a mini compiler of our own, then emit the IL code dynamically.