Table of Contents

Class LocalFunctionDecompiler

Namespace
ICSharpCode.Decompiler.IL.Transforms
Assembly
ICSharpCode.Decompiler.dll

Decompiler step for C# 7.0 local functions

public class LocalFunctionDecompiler : IILTransform
Inheritance
LocalFunctionDecompiler
Implements
Inherited Members

Constructors

LocalFunctionDecompiler()

public LocalFunctionDecompiler()

Methods

IsLocalFunctionDisplayClass(PEFile, TypeDefinitionHandle, ILTransformContext)

public static bool IsLocalFunctionDisplayClass(PEFile module, TypeDefinitionHandle typeHandle, ILTransformContext context = null)

Parameters

module PEFile
typeHandle TypeDefinitionHandle
context ILTransformContext

Returns

bool

IsLocalFunctionMethod(PEFile, MethodDefinitionHandle, ILTransformContext)

public static bool IsLocalFunctionMethod(PEFile module, MethodDefinitionHandle methodHandle, ILTransformContext context = null)

Parameters

module PEFile
methodHandle MethodDefinitionHandle
context ILTransformContext

Returns

bool

IsLocalFunctionMethod(IMethod, ILTransformContext)

public static bool IsLocalFunctionMethod(IMethod method, ILTransformContext context)

Parameters

method IMethod
context ILTransformContext

Returns

bool

LocalFunctionNeedsAccessibilityChange(PEFile, MethodDefinitionHandle)

public static bool LocalFunctionNeedsAccessibilityChange(PEFile module, MethodDefinitionHandle methodHandle)

Parameters

module PEFile
methodHandle MethodDefinitionHandle

Returns

bool

Run(ILFunction, ILTransformContext)

The transform works like this:

local functions can either be used in method calls, i.e., call and callvirt instructions, or can be used as part of the "delegate construction" pattern, i.e., newobj Delegate(<target-expression>, ldftn <method>).

As local functions can be declared practically anywhere, we have to take a look at all use-sites and infer the declaration location from that. Use-sites can be call, callvirt and ldftn instructions. After all use-sites are collected we construct the ILAst of the local function and add it to the parent function. Then all use-sites of the local-function are transformed to a call to the LocalFunctionMethod or a ldftn of the LocalFunctionMethod. In a next step we handle all nested local functions. After all local functions are transformed, we move all local functions that capture any variables to their respective declaration scope.
public void Run(ILFunction function, ILTransformContext context)

Parameters

function ILFunction
context ILTransformContext