Looking at the code, it's not necessarily wrong. I agree it's confusing though.
So, names for local variables are not stored in the assembly, they're stored in the debug symbol file. The reasoning is as follow: ToString tries to get a meaningful representation based on the only information: the index, while there's not actual name for the variable, hence the empty string. I don't know why ILSpy would show something different, but as it is, the .IsSpecialName is simply checking the bits for the attributes of the method, I don't think there's a bug in that part. Jb On Thu, Mar 13, 2014 at 4:10 PM, Jonathan Piché <[email protected]> wrote: > Hi, > > I am reading a ldloc instruction and trying to retrieve the name (or index) > of the referenced variable: > > var ldlocInstruction = body.Instructions.FirstOrDefault(i => i.OpCode == > OpCodes.LdLoc); > var ldlocVariable = body.Variables.Single(v => v.Name == > ldlocInstruction.Operand.ToString()); > > In most cases, it works fine. However some methods (typically the ones that > show the variable name as V_0, V_1, etc) will return an empty string ("") > for v.Name. The weird thing though, is that v.ToString() will correctly give > me V_0, V_1! > > As it stands now, my issue is fixed when using .ToString() on the > VariableDefinition instead of looking up the .Name(). I am posting here in > case this is a bug in Cecil. > > Something else that I found weird, is that the method is shown as > "specialname" in ILSpy, but the MethodDefinition from Cecil has > .IsSpecialName set to false. > > My target assembly was compiled using Microsoft .NET and not mono, in case > it changes anything. > > Thanks! > > Joe > > -- > -- > -- > mono-cecil > --- > You received this message because you are subscribed to the Google Groups > "mono-cecil" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- -- -- mono-cecil --- You received this message because you are subscribed to the Google Groups "mono-cecil" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
