Table of Contents

Class CSharpDecompiler

Namespace
ICSharpCode.Decompiler.CSharp
Assembly
ICSharpCode.Decompiler.dll

Main class of the C# decompiler engine.

public class CSharpDecompiler
Inheritance
CSharpDecompiler
Inherited Members

Remarks

Instances of this class are not thread-safe. Use separate instances to decompile multiple members in parallel. (in particular, the transform instances are not thread-safe)

Constructors

CSharpDecompiler(PEFile, IAssemblyResolver, DecompilerSettings)

Creates a new CSharpDecompiler instance from the given module using the given assemblyResolver and settings.

public CSharpDecompiler(PEFile module, IAssemblyResolver assemblyResolver, DecompilerSettings settings)

Parameters

module PEFile
assemblyResolver IAssemblyResolver
settings DecompilerSettings

CSharpDecompiler(DecompilerTypeSystem, DecompilerSettings)

Creates a new CSharpDecompiler instance from the given typeSystem and the given settings.

public CSharpDecompiler(DecompilerTypeSystem typeSystem, DecompilerSettings settings)

Parameters

typeSystem DecompilerTypeSystem
settings DecompilerSettings

CSharpDecompiler(string, DecompilerSettings)

Creates a new CSharpDecompiler instance from the given fileName using the given settings.

public CSharpDecompiler(string fileName, DecompilerSettings settings)

Parameters

fileName string
settings DecompilerSettings

CSharpDecompiler(string, IAssemblyResolver, DecompilerSettings)

Creates a new CSharpDecompiler instance from the given fileName using the given assemblyResolver and settings.

public CSharpDecompiler(string fileName, IAssemblyResolver assemblyResolver, DecompilerSettings settings)

Parameters

fileName string
assemblyResolver IAssemblyResolver
settings DecompilerSettings

Properties

AstTransforms

C# AST transforms.

public IList<IAstTransform> AstTransforms { get; }

Property Value

IList<IAstTransform>

CancellationToken

Token to check for requested cancellation of the decompilation.

public CancellationToken CancellationToken { get; set; }

Property Value

CancellationToken

DebugInfoProvider

Gets or sets the optional provider for debug info.

public IDebugInfoProvider DebugInfoProvider { get; set; }

Property Value

IDebugInfoProvider

DocumentationProvider

Gets or sets the optional provider for XML documentation strings.

public IDocumentationProvider DocumentationProvider { get; set; }

Property Value

IDocumentationProvider

ILTransforms

IL transforms.

public IList<IILTransform> ILTransforms { get; }

Property Value

IList<IILTransform>

TypeSystem

The type system created from the main module and referenced modules.

public IDecompilerTypeSystem TypeSystem { get; }

Property Value

IDecompilerTypeSystem

Methods

AddPartialTypeDefinition(PartialTypeInfo)

public void AddPartialTypeDefinition(PartialTypeInfo info)

Parameters

info PartialTypeInfo

CreateILTransformContext(ILFunction)

Creates an ILTransformContext for the given function.

public ILTransformContext CreateILTransformContext(ILFunction function)

Parameters

function ILFunction

Returns

ILTransformContext

CreateSequencePoints(SyntaxTree)

Creates sequence points for the given syntax tree.

This only works correctly when the nodes in the syntax tree have line/column information.

public Dictionary<ILFunction, List<SequencePoint>> CreateSequencePoints(SyntaxTree syntaxTree)

Parameters

syntaxTree SyntaxTree

Returns

Dictionary<ILFunction, List<SequencePoint>>

Decompile(IEnumerable<EntityHandle>)

Decompile the specified types and/or members.

public SyntaxTree Decompile(IEnumerable<EntityHandle> definitions)

Parameters

definitions IEnumerable<EntityHandle>

Returns

SyntaxTree

Decompile(params EntityHandle[])

Decompile the specified types and/or members.

public SyntaxTree Decompile(params EntityHandle[] definitions)

Parameters

definitions EntityHandle[]

Returns

SyntaxTree

DecompileAsString(IEnumerable<EntityHandle>)

Decompile the specified types and/or members.

public string DecompileAsString(IEnumerable<EntityHandle> definitions)

Parameters

definitions IEnumerable<EntityHandle>

Returns

string

DecompileAsString(params EntityHandle[])

Decompile the specified types and/or members.

public string DecompileAsString(params EntityHandle[] definitions)

Parameters

definitions EntityHandle[]

Returns

string

DecompileModuleAndAssemblyAttributes()

Decompile assembly and module attributes.

public SyntaxTree DecompileModuleAndAssemblyAttributes()

Returns

SyntaxTree

DecompileModuleAndAssemblyAttributesToString()

Decompile assembly and module attributes.

public string DecompileModuleAndAssemblyAttributesToString()

Returns

string

DecompileType(FullTypeName)

Decompile the given type.

public SyntaxTree DecompileType(FullTypeName fullTypeName)

Parameters

fullTypeName FullTypeName

Returns

SyntaxTree

Remarks

Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition. Note that decompiling types from modules other than the main module is not supported.

DecompileTypeAsString(FullTypeName)

Decompile the given type.

public string DecompileTypeAsString(FullTypeName fullTypeName)

Parameters

fullTypeName FullTypeName

Returns

string

Remarks

Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition.

DecompileTypes(IEnumerable<TypeDefinitionHandle>)

Decompile the given types.

public SyntaxTree DecompileTypes(IEnumerable<TypeDefinitionHandle> types)

Parameters

types IEnumerable<TypeDefinitionHandle>

Returns

SyntaxTree

Remarks

Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definitions.

DecompileTypesAsString(IEnumerable<TypeDefinitionHandle>)

Decompile the given types.

public string DecompileTypesAsString(IEnumerable<TypeDefinitionHandle> types)

Parameters

types IEnumerable<TypeDefinitionHandle>

Returns

string

Remarks

Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definitions.

DecompileWholeModuleAsSingleFile()

Decompiles the whole module into a single syntax tree.

public SyntaxTree DecompileWholeModuleAsSingleFile()

Returns

SyntaxTree

DecompileWholeModuleAsSingleFile(bool)

Decompiles the whole module into a single syntax tree.

public SyntaxTree DecompileWholeModuleAsSingleFile(bool sortTypes)

Parameters

sortTypes bool

If true, top-level-types are emitted sorted by namespace/name. If false, types are emitted in metadata order.

Returns

SyntaxTree

DecompileWholeModuleAsString()

Decompiles the whole module into a single string.

public string DecompileWholeModuleAsString()

Returns

string

GetAstTransforms()

Returns all built-in transforms of the C# AST pipeline.

public static List<IAstTransform> GetAstTransforms()

Returns

List<IAstTransform>

GetCodeMappingInfo(PEFile, EntityHandle)

Determines the "code-mappings" for a given TypeDef or MethodDef. See CodeMappingInfo for more information.

public static CodeMappingInfo GetCodeMappingInfo(PEFile module, EntityHandle member)

Parameters

module PEFile
member EntityHandle

Returns

CodeMappingInfo

GetILTransforms()

Returns all built-in transforms of the ILAst pipeline.

public static List<IILTransform> GetILTransforms()

Returns

List<IILTransform>

MemberIsHidden(PEFile, EntityHandle, DecompilerSettings)

Determines whether a member should be hidden from the decompiled code. This is used to exclude compiler-generated code that is handled by transforms from the output.

public static bool MemberIsHidden(PEFile module, EntityHandle member, DecompilerSettings settings)

Parameters

module PEFile

The module containing the member.

member EntityHandle

The metadata token/handle of the member. Can be a TypeDef, MethodDef or FieldDef.

settings DecompilerSettings

THe settings used to determine whether code should be hidden. E.g. if async methods are not transformed, async state machines are included in the decompiled code.

Returns

bool