Getting source location from TypeDefinition with Mono.Cecil

127 views Asked by At

I would like to determine which source file defines a specific type using Mono.Cecil.

For methods, I can use the SequencePoint collection (for example, I could grab the first SequencePoint and fetch the Url of it's Document). I'm assuming this would always work as long as the PDBs are loaded since even empty methods should have at least one instruction (nop):

      if (methodDefinition.DebugInformation.HasSequencePoints) {
        var firstSequencePoint = methodDefinition.DebugInformation.SequencePoints[0];
        return firstSequencePoint.Document.Url;
      }

However, for types, I am not sure how this would work. Do the PDB files even contain the mapping between a type and a document? Obviously a type can be defined across multiple documents (in case of partial classes, for instance) which is fine - but is this information actually available? If yes, is it exposed in Mono.Cecil? Mono.Cecil.Cil.PortablePdbReader does read CustomDebugInformation for a module but I don't think this is it (I looked at the raw data and it doesn't contain anything of interest).

0

There are 0 answers