获取字段的行号而不使用c#解析器

时间:2011-04-13 20:55:28

标签: c# system.diagnostics line-numbers fieldinfo

我想得到一个类型字段的行#。

要在方法中获取语句的行#,这很简单:

Type type = typeof(MyClass);
MethodInfo methodInfo = type.GetMethod("SomeMethod");
int token = methodInfo.MetadataToken;
ISymbolReader reader = SymUtil.GetSymbolReaderForFile(@"dllName", null); // from mike stall's pdb2xml
ISymbolMethod methodSymbol = reader.GetMethod(new SymbolToken(token));
int count = methodSymbol.SequencePointCount;
ISymbolDocument[] docs = new ISymbolDocument[count];
int[] startColumn = new int[count];
int[] endColumn = new int[count];
int[] startRow = new int[count];
int[] endRow = new int[count];
method.GetSequencePoints(offsets, docs, startRow, startColumn, endRow, endColumn);

不幸的是,获取构造函数的局部变量是不够的,因为某些类型的变量可以是const / static。

0 个答案:

没有答案