开发者

Get line numbers of fields without using a c# parser

I would like to get the line #s of a type's fields.

To get the line #'s of the statements in a method it is simple enough:

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);

Unfortunately it is not enough to get a constructor's local variables, as some of the type's variables can be const/static.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜