Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Reflection Emit

Back to Forum: Tech Off
  • User profile image

    I'm brushing up on some of the finer points of c# at the moment, reading "Programming C#" by Jesse Liberty, it's full of really neat stuff.

    The author has a good chapter on Reflection, and specifically emitting op codes to dynamically create an IL class.

    Obviously the performance on this is fantastic, but I wonder, as a business logic / web apps developer, is there any use in this technique for me?

    I'd love to take a crack at it but in traditional n-tier, business apps what reason would I have?

  • 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.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.