SequencePoint 結構

定義

表示可攜式 PDB 序列點。

public value class SequencePoint : IEquatable<System::Reflection::Metadata::SequencePoint>
public readonly struct SequencePoint : IEquatable<System.Reflection.Metadata.SequencePoint>
public struct SequencePoint : IEquatable<System.Reflection.Metadata.SequencePoint>
type SequencePoint = struct
Public Structure SequencePoint
Implements IEquatable(Of SequencePoint)
繼承
SequencePoint
實作

範例

此範例展示了如何讀取由元資料標記定義的方法序列點,並顯示其原始碼行映射:

public static void ReadSourceLineData(string pdbPath, int methodToken)
{
    // Determine method row number
    EntityHandle ehMethod = MetadataTokens.EntityHandle(methodToken);

    if (ehMethod.Kind != HandleKind.MethodDefinition)
    {
        Console.WriteLine($"Invalid token kind: {ehMethod.Kind}");
        return;
    }

    int rowNumber = MetadataTokens.GetRowNumber(ehMethod);

    // MethodDebugInformation table is indexed by same row numbers as MethodDefinition table
    MethodDebugInformationHandle hDebug = MetadataTokens.MethodDebugInformationHandle(rowNumber);

    // Open Portable PDB file
    using var fs = new FileStream(pdbPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    using MetadataReaderProvider provider = MetadataReaderProvider.FromPortablePdbStream(fs);
    MetadataReader reader = provider.GetMetadataReader();

    if (rowNumber > reader.MethodDebugInformation.Count)
    {
        Console.WriteLine("Error: Method row number is out of range");
        return;
    }

    // Print source line information as console table
    MethodDebugInformation di = reader.GetMethodDebugInformation(hDebug);
    Console.WriteLine("IL offset | Start line | Start col. | End line | End col. |");

    foreach (SequencePoint sp in di.GetSequencePoints())
    {
        if (sp.IsHidden)
        {
            Console.WriteLine($"{sp.Offset.ToString().PadLeft(9)} | (hidden sequence point)");
        }
        else
        {
            Console.WriteLine("{0} |{1} |{2} |{3} |{4} |", 
                sp.Offset.ToString().PadLeft(9), 
                sp.StartLine.ToString().PadLeft(11),
                sp.StartColumn.ToString().PadLeft(11),
                sp.EndLine.ToString().PadLeft(9),
                sp.EndColumn.ToString().PadLeft(9));
        }
    }
}

備註

序列點是一個結構,包含 IL 偏移量與該 IL 編譯來源文件中對應行號和欄號之間的映射。 序列點儲存在可攜式 PDB 除錯符號表中 MethodDebugInformation 。 如需詳細資訊,請參閱 可攜式 PDB v1.0:格式規格

欄位

名稱 Description
HiddenLine

指定隱藏序列點的行號值。

屬性

名稱 Description
Document

取得包含該序列點的原始文件。

EndColumn

取得該序列點最後一個字元的欄號。

EndLine

取得該序列點最後一個字元的行號。

IsHidden

會得到一個值,表示該序列點是否被隱藏。

Offset

取得此序列點從方法主體起始點的 IL 偏移量,單位為位元組。

StartColumn

取得該序列點中第一個字元的欄號。

StartLine

取得該序列點中第一個字元的行號。

方法

名稱 Description
Equals(Object)

表示當前序列點是否等於指定物件。

Equals(SequencePoint)

指出目前的物件是否等於相同類型的另一個物件。

GetHashCode()

取得該序列點的雜湊碼。

適用於