Hello,

If I understand well, you are trying to compile IL without the need to
call ilasm or any other exe file. If so what you need is an IL files
parser. So you will have to choose between using a first, second (I
mean Microsoft's) or third party solution.

For a third party IL parser I prefer not to point out any one because
I haven't use any, still you can find some to try and test by
googling.

For a second party one (I mean Microsoft's) It seems that you can get
it here: 
http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&displaylang=en
though, I haven't downloaded that...

Lastly for a first party parser, I would recomend to implement it with
Irony (get it on CodePlex) and C#, I don't know about an already
compiled grammar for IL, but you can get the info you may need to
create the parser (using Irony or not) from the formal definition at
ECMA: http://www.ecma-international.org/publications/standards/Ecma-335.htm

Irony here: http://irony.codeplex.com/

And sorry, it wont be as few lines as in the code you posted. Still,
you will find help using Irony in it's discussions list.

Well, anyway, after parsing the file (Irony must give you a data
structure with the info readed from the file, that shouldn't be harder
to interpret than a loop with a switch), you'll need to use reflection
to write the code as in the examples you mentioned, and then save that
to disk.

I understand if you are not up to write a parser, but still Irony has
done the job easier than the in the age of yacc and bison, yet it has
it's flaws too. now.. what's wrong with using ilsam anyway? Is just
that it's async? I think it's not a big deal.

On 1 mayo, 01:37, nitefrog <[email protected]> wrote:
> I would like to take a file that is an IL file, and at run time
> compile it back to an exe.
>
> Right now I can use process.start to fire off the command line with
> parameters (ilasm.exe) but I would like to automate this process from
> a C# service I will create.
>
> Is there a way to do this with reflection and reflection.emit?
>
> While this works:
>
> string rawText = File.ReadAllText(string.Format("c:\\temp\\{0}.il",
> Utility.GetAppSetting("baseName")), Encoding.ASCII);
>
> rawText = rawText.Replace("[--STRIP--]", guid);
>
> File.Delete(string.Format("c:\\temp\\{0}.il",
> Utility.GetAppSetting("baseName")));
>
> File.WriteAllText(string.Format("c:\\temp\\{0}.il",
> Utility.GetAppSetting("baseName")),rawText, Encoding.ASCII);
>
> pi = new ProcessStartInfo();
> pi.WindowStyle = ProcessWindowStyle.Hidden;
> pi.FileName = "\"" + ilasm + "\"";
> pi.Arguments = string.Format("c:\\temp\\{0}.il",
> Utility.GetAppSetting("baseName"));
>
> using(Process p = Process.Start(pi))
> {
>     p.WaitForExit();
>
> }
>
> It is not ideal as I really would like this to be a streamlined
> process.
>
> I have seen examples of creating the IL at runtime, then saving, but I
> need to use the IL I already have in file form and compile it back to
> an exe.
>
> Thanks.

Reply via email to