Click here to Skip to main content
Click here to Skip to main content

IlPad

By , 21 Sep 2012
 

Download source 

Download executable 

 

Introduction  

A while back, I was trying to improve the efficiency of a program and in doing so, I needed to view the MSIL of the assembly I was working on. It soon became very tedious to have to build my program then switch over to Microsoft Ildasm to have to keep looking at my disassembly. I tried looking on the Internet for something that would let me view my C# code and my IL code together, but I found no such thing. Hence IlPad was born. 

What it does 

IlPad opens up with 4 panels. The top panel is a text box where you can enter C# code. It can be a whole program or just part of a class. To the right is another panel which shows which assemblies you currently have referenced. There is a button that opens up where you can reference even more assemblies if you need to. Below the C# editor is a button. Clicking on this button will compile your snippet and the resulting IL code is shown in another text box below that. If there are any errors in your C# code, the errors will be outputted to a list box at the bottom of IlPad. The list box will give you a description of the error along with a line number where the error occurred. IlPad is that easy to use! 

In addition to all that, I have included two sample snippet codes. By clicking on either of the two snippet code buttons at the top of the window, the text box will automatically fill in a code snippet. Both of these snippets run without having to reference any additional assemblies. 

How IlPad works 

IlPad works by taking advantage of the CSharpCodeProvider class. This class will let you dynamically compile C# code into either an in-memory assembly or an assembly outputted to a file. Here is a snippet of code from IlPad that does the compilation:

            var options = new Dictionary<string, string> {{"CompilerVersion", "v4.0"}};
            var provider = new CSharpCodeProvider(options);
            var parms = new CompilerParameters
                {
                    CompilerOptions = @"/lib:C:\Windows\assembly\GAC /target:library",
                    GenerateExecutable = true,
                    GenerateInMemory = false
                };
            parms.ReferencedAssemblies.Add("System.dll");
            foreach (string item in lbReferences.Items)
            {
                parms.ReferencedAssemblies.Add(item + ".dll");
            }
            string outFile = Path.GetTempFileName();
            string ilOutFile = Path.GetTempFileName();
            string ildasm = Path.GetTempFileName() + ".exe";
            parms.OutputAssembly = outFile;
            CompilerResults res = provider.CompileAssemblyFromSource(parms, txtInputProgram.Text); 

IlPad targets .NET 4.0. IlPad could be made to run in .NET 3.5, if needed. IlPad creates a temporary file to store the compiled assembly. Once the assembly is successfully created, IlPad runs IlDasm. IlDasm is a disassembler created by Microsoft that disassembles .NET assemblies into MSIL code.  

Things yet to do 

When I get more time, thee are some things I'd like to do to improve IlPad. Here is a short to do list:

  • Add VB.NET support
  • Improve the "Add a Reference" dialog
  • Syntax highlighting (both source code and IL code) 
  • Automatic code formatting
  • Possibly add F# support 
  • Create a snippet library and add more snippets
  • Ability to create and store your own snippets in the snippet library 
Of course, if anyone has any suggestions or things they'd like to see added, I'd love to hear any ideas! 

History

1.0 - Initial Release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

icemanind
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionFour Star!memberkodabd25 Sep '12 - 5:04 
GeneralMy vote of 5memberGunjan Bhasin22 Sep '12 - 8:23 
GeneralMy vote of 2 [modified]memberPaul Tait21 Sep '12 - 20:19 
GeneralRe: My vote of 2membericemanind22 Sep '12 - 3:18 
GeneralRe: My vote of 2memberWinfried Lötzsch22 Sep '12 - 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130513.1 | Last Updated 22 Sep 2012
Article Copyright 2012 by icemanind
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid