ILSpy decompile a delegate

628 Views Asked by At

ILSpy can decompile assemblies. Can it decompile a delegate? I would imagine a CSharpDecompiler constructor overload accepting a Func or an Action as an argument instead of a "string fileName". Is it technically feasible, are there any future plans to support this? Any suggested work-arounds?

Example of what I had in mind....

Action<int> myAction = i =>
{
    // body to be decompiled
};
var decompiler = new CSharpDecompiler(myAction, new DecompilerSettings());
decompiler.DecompileAsString();
1

There are 1 best solutions below

3
chr1st0scli On BEST ANSWER

An official ILSpy member has answered in the project's discussion section:

"It's not possible, because the decompiler requires a full PE image containing IL code and .NET metadata tables"

https://github.com/icsharpcode/ILSpy/discussions/2581