开发者

Get line numbers of fields without using a c# parser

开发者 https://www.devze.com 2023-02-25 04:35 出处:网络
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:

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

精彩评论

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

关注公众号