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
PEFileassemblyResolver
IAssemblyResolversettings
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
DecompilerTypeSystemsettings
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
stringsettings
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
stringassemblyResolver
IAssemblyResolversettings
DecompilerSettings
Properties
AstTransforms
C# AST transforms.
public IList<IAstTransform> AstTransforms { get; }
Property Value
CancellationToken
Token to check for requested cancellation of the decompilation.
public CancellationToken CancellationToken { get; set; }
Property Value
DebugInfoProvider
Gets or sets the optional provider for debug info.
public IDebugInfoProvider DebugInfoProvider { get; set; }
Property Value
DocumentationProvider
Gets or sets the optional provider for XML documentation strings.
public IDocumentationProvider DocumentationProvider { get; set; }
Property Value
ILTransforms
IL transforms.
public IList<IILTransform> ILTransforms { get; }
Property Value
TypeSystem
The type system created from the main module and referenced modules.
public IDecompilerTypeSystem TypeSystem { get; }
Property Value
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
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
Decompile(IEnumerable<EntityHandle>)
Decompile the specified types and/or members.
public SyntaxTree Decompile(IEnumerable<EntityHandle> definitions)
Parameters
definitions
IEnumerable<EntityHandle>
Returns
Decompile(params EntityHandle[])
Decompile the specified types and/or members.
public SyntaxTree Decompile(params EntityHandle[] definitions)
Parameters
definitions
EntityHandle[]
Returns
DecompileAsString(IEnumerable<EntityHandle>)
Decompile the specified types and/or members.
public string DecompileAsString(IEnumerable<EntityHandle> definitions)
Parameters
definitions
IEnumerable<EntityHandle>
Returns
DecompileAsString(params EntityHandle[])
Decompile the specified types and/or members.
public string DecompileAsString(params EntityHandle[] definitions)
Parameters
definitions
EntityHandle[]
Returns
DecompileModuleAndAssemblyAttributes()
Decompile assembly and module attributes.
public SyntaxTree DecompileModuleAndAssemblyAttributes()
Returns
DecompileModuleAndAssemblyAttributesToString()
Decompile assembly and module attributes.
public string DecompileModuleAndAssemblyAttributesToString()
Returns
DecompileType(FullTypeName)
Decompile the given type.
public SyntaxTree DecompileType(FullTypeName fullTypeName)
Parameters
fullTypeName
FullTypeName
Returns
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
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
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
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
DecompileWholeModuleAsSingleFile(bool)
Decompiles the whole module into a single syntax tree.
public SyntaxTree DecompileWholeModuleAsSingleFile(bool sortTypes)
Parameters
sortTypes
boolIf true, top-level-types are emitted sorted by namespace/name. If false, types are emitted in metadata order.
Returns
DecompileWholeModuleAsString()
Decompiles the whole module into a single string.
public string DecompileWholeModuleAsString()
Returns
GetAstTransforms()
Returns all built-in transforms of the C# AST pipeline.
public static List<IAstTransform> GetAstTransforms()
Returns
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
PEFilemember
EntityHandle
Returns
GetILTransforms()
Returns all built-in transforms of the ILAst pipeline.
public static List<IILTransform> GetILTransforms()
Returns
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
PEFileThe module containing the member.
member
EntityHandleThe metadata token/handle of the member. Can be a TypeDef, MethodDef or FieldDef.
settings
DecompilerSettingsTHe 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.