Get line numbers of fields without using a c# parser

让人想犯罪 __ 提交于 2019-12-05 01:06:52

问题


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.

来源:https://stackoverflow.com/questions/5655507/get-line-numbers-of-fields-without-using-a-c-sharp-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!