I'm hoping someone might be able to point me in the right direction as
I'm a newbie to Mono.Cecil.

How should one go about getting the file name and line number of the
elements, types, methods, etc., in an assembly?

After reading through various posts it looks like an ISymbolReader can
be passed to a ModuleDefinition but I'm not sure where to go from
there. Little help?

Thanks.

        private static void TestMonoCecil(string assemblyFilePath)
        {
            string nameWithoutExt =
Path.GetFileNameWithoutExtension(assemblyFilePath);
            string directory =
Path.GetDirectoryName(assemblyFilePath);
            const string pdbFileExt = ".pdb";
            string symbolFilePath = Path.Combine(directory,
nameWithoutExt + pdbFileExt);
            bool hasSymbolFile = File.Exists(symbolFilePath);

            ReaderParameters parameters = null;
            if (hasSymbolFile)
            {
                parameters = new ReaderParameters();
                parameters.SymbolReaderProvider = new
PdbReaderProvider();
                parameters.ReadingMode = ReadingMode.Immediate;
            }

            AssemblyDefinition assembly =
AssemblyDefinition.ReadAssembly(assemblyFilePath, parameters);
            foreach (ModuleDefinition module in assembly.Modules)
            {
                if (!module.HasTypes)
                {
                    continue;
                }

                ISymbolReader symbolReader =
parameters.SymbolReaderProvider.GetSymbolReader(module,
symbolFilePath);
                module.ReadSymbols(symbolReader);

-- 
--
mono-cecil

Reply via email to