Question

In previous release of .NET Reflector, I was able to get the namespace of an instruction inside a function but now I can't and the doc does not exist.

Red Gate's .NET Reflector 6.8.2.5 (last free version)

This line was working but not now : instruction.Value.declaringtype.namespace.ToString

How do I get the namespace of an instruction?

Thx

Private Sub DesassamblerDLL(ByVal strDLLFile As String)
    Dim serviceProvider As New Reflector.ApplicationManager(Nothing)
    Dim assemblyManager As Reflector.CodeModel.IAssemblyManager
    Dim objAssembly As Reflector.CodeModel.IAssembly
    Dim objMod As Reflector.CodeModel.IModule
    Dim typeDeclaration As Reflector.CodeModel.ITypeDeclaration
    Dim methodDeclaration As Reflector.CodeModel.IMethodDeclaration

    assemblyManager = serviceProvider.GetService(GetType(Reflector.CodeModel.IAssemblyManager))
    objAssembly = assemblyManager.LoadFile(strDLLFile)

    For Each objMod In objAssembly.Modules
        For Each typeDeclaration In objMod.Types
            For Each methodDeclaration In typeDeclaration.Methods
                Dim methodBody As Reflector.CodeModel.IMethodBody = methodDeclaration.Body
                If Not methodBody Is Nothing Then
                    Dim instruction As Reflector.CodeModel.IInstruction
                    For Each instruction In methodBody.Instructions
                        str = instruction.Value.declaringtype.namespace.ToString
                    Next
                End If
            Next
        Next
    Next
End Sub
Was it helpful?

Solution

I made it with the help of Clive from http://forums.reflector.net/questions/2226/namespace-of-an-instruction-net-reflector.

Imports system.Reflection.Emit

Select Case instruction.Code
    Case OpCodes.Call.Value, OpCodes.Calli.Value, OpCodes.Callvirt.Value
        Dim targetMethodReference As Reflector.CodeModel.IMethodReference = instruction.Value
        Dim method As Reflector.CodeModel.IMethodDeclaration = targetMethodReference.Resolve
        Dim typeReference As Reflector.CodeModel.ITypeReference = method.DeclaringType
        ...
End Select
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top