目前,我正在尝试从IL字节codeS和PDB文件源$ C $ C, 即时到达的地步,我可以从IL和反射生成源$ C $ C 我所知道的局部变量名的名称包括在PDB文件。 我的问题是如何把它找回来?我应该使用什么样的库来处理PDB文件(如有)或我应该c写自己的$ C $?我在哪里可以找到有关PDB文件格式的信息? 目前在生成的源$ C $ C我使用自动生成的值,局部变量,但我想改变这种状况,因为我相信这是有可能找到的信息回来,如果您在您的处置有pdb文件。 我试图寻找对谷歌,但我没有发现任何有用的信息。
i'm currently trying to retrieve source code from IL bytecodes and PDB files, i'm arrived to the point where i can generate source code from IL and reflection i know the name of local variable names is included in the pdb file. My question is how can i find it back ? what libs should i use to handle the pdb files (if any) or should i write the code myself ? where can i find information about pdb file format ? currently in the generated sourcecode i'm using auto generated values for local variables but i want to change that as i believe it is possible to find that information back if you have pdb files at your disposal. I tried to look on google but i didnt find any usefull informations.
在此先感谢您的答复;)
Thanks in advance for you replies ;)
下面是如何从一个MethodInfo的使用类型 System.Diagnostics.SymbolStore
读取本地变量名:
Here's how to read local variable names from a MethodInfo using the types in System.Diagnostics.SymbolStore
:
public class LocalVariableNameReader
{
Dictionary<int, string> _names = new Dictionary<int, string> ();
public string this [int index]
{
get
{
if (!_names.ContainsKey (index)) return null;
return _names [index];
}
}
public LocalVariableNameReader (MethodInfo m)
{
ISymbolReader symReader = SymUtil.GetSymbolReaderForFile (m.DeclaringType.Assembly.Location, null);
ISymbolMethod met = symReader.GetMethod (new SymbolToken (m.MetadataToken));
VisitLocals (met.RootScope);
}
void VisitLocals (ISymbolScope iSymbolScope)
{
foreach (var s in iSymbolScope.GetLocals ()) _names [s.AddressField1] = s.Name;
foreach (var c in iSymbolScope.GetChildren ()) VisitLocals (c);
}
}
在 SymUtil
类来自的这个例子。