4

タイプのフィールドの行番号を取得したいと思います。

メソッド内のステートメントの行番号を取得するには、次のように簡単です。

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 になる可能性があるためです。

4

0 に答える 0