"(E-Mail Removed)" wrote:
> I'd like to take a string containing MSIL code, assemble it, execute
> it, and receive the result all from my running C# application.
>
> So far I've managed to manually create some MSIL code that I can
> successfully assemble with ilasm and execute at the DOS prompt, and
> I've read up on System.Reflection.Emit and CodeDom, but I don't see how
> to do this. It looks like I would have to write a whole
> System.CodeDom.Compiler.CodeCompiler; I hope I'm wrong about that,
> since it seems that the whole purpose of that class is to generate the
> MSIL from a source language, but I've already got the MSIL.
Does the CIL [Common Intermediate Language - the now-old replacement
name for MSIL] have to come from a string? You say you're creating
code to pass to ILASM - could the process that creates that code just
call Emit directly?
Emit is reasonably straightforward, but if you have to read a string,
you have to write an assembler, which IS a full-blown compiler, albeit
a very rudimentary one. You have to tokenize, detect bad syntax, &c.
--
programmer, author
http://www.midnightbeach.com
and father
http://www.midnightbeach.com/hs