Doesn't determining the variable name require the PDB? Never tried it before, but try loading the PDB into Cecil after the assembly.
On Sat, May 9, 2009 at 6:59 AM, Timwi <[email protected]> wrote: > > Hi, > > I'm trying to get a list of the names of the local variables in a > specific method. > > So I'm using something like this ... > foreach (var m in myLibrary.Modules.Cast<ModuleDefinition> > ()) { > foreach (var t in m.Types.Cast<TypeDefinition>()) { > foreach (var e in t.Methods.Cast<MethodDefinition> > ()) { > foreach (var v in > e.Body.Variables.Cast<VariableDefinition>()) { > Console.WriteLine(v.Name); > } > } > } > } > > Unfortunately, I only get "V_0", "V_1", etc., not the real variable > names. > > I tried actually changing the names to something like "a", "b", etc., > by assigning to v.Name, but Red Gate's .NET Reflector still shows them > with their original name, so the name wasn't changed. > > Renaming methods by assigning to m.Name appears to work. Reflector > shows the new names. > > Why doesn't this work for variables, and how do I make it work? > > Thanks! > Timwi > > > -- Jono --~--~---------~--~----~------------~-------~--~----~ -- mono-cecil -~----------~----~----~----~------~----~------~--~---
