locked
Dynamic Method from C# Code Snippet RRS feed

  • Question

  • We have been playing around with Dynamic Method to generate code on the fly, but the only problem is it goes well with IL code and there is no capability that can take C# code snippet, similar to what codedom provider does.

    Does anyone know how to generate dynamic method using C# code snippet ?
    Thursday, March 12, 2009 1:45 PM

Answers

  • Just write it out to file and call csc.exe using the Process class.  You may have to wrap the code snippet in a class or namespace depending on what is considered a "code snippet", but it should work.  Jon Skeet's Snippy program does what you're wanting to do.  Check it out and study it's code.  It might be exactly what you're looking for.
    David Morton - http://blog.davemorton.net/
    • Marked as answer by Zhi-Xin Ye Tuesday, March 17, 2009 10:22 AM
    Thursday, March 12, 2009 1:53 PM