3

I'm currently working on a compiler(transpiler?) from methbases to C# expression trees which uses ILSpy. The general problem I'm having is linking System.Reflection.MethodBases to the correct methodDeclarations in the NRefactory AST outputted by ILSpy.

I'm well aware of ILSpy's ability to give an AST for an entire assembly, such as:

            AssemblyDefinition pAssembly = AssemblyDefinition.ReadAssembly(filename, parameters);
            AstBuilder pDecompiler = new AstBuilder(new DecompilerContext(pAssembly.MainModule));

            pDecompiler.AddAssembly(pAssembly);
            pDecompiler.RunTransformations();
            ast = pDecompiler.SyntaxTree;

However, would it be possible to invoke ILSpy for a small snippet of IL, such as you can obtain by calling:

m.GetMethodBody().GetILAsByteArray()

This would make it very easy to solve the methodbase pairing problem, to which I have a very horrid solution at the moment.

Nick
  • 920
  • 1
  • 7
  • 21
  • May be you can create a temporary assembly by compiling it programmatically using this https://support.microsoft.com/en-us/help/304655/how-to-programmatically-compile-code-using-c-compiler then just pass this temporary assembly to IlSpy. – Isma Oct 18 '17 at 15:13
  • Perhaps? This would presumably have problems in that the method may reference types that aren't defined in the method, so that assembly would be invalid – Nick Oct 19 '17 at 09:17

0 Answers0