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 位移與對應行號與數據行編號之間的對應。 序列點會儲存在 MethodDebugInformation 可攜式 PDB 偵錯符號的數據表中。 如需詳細資訊,請參閱可攜式 PDB v1.0:格式規格

欄位

HiddenLine

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

屬性

Document

取得包含這個序列點的源檔。

EndColumn

取得這個序列點中最後一個字元的數據行編號。

EndLine

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

IsHidden

取得值,這個值表示這個序列點是否隱藏。

Offset

從方法主體的開頭取得這個序列點的 IL 位移,以位元組為單位。

StartColumn

取得這個序列點中第一個字元的數據行編號。

StartLine

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

方法

Equals(Object)

指出目前的序列點是否等於指定的物件。

Equals(SequencePoint)

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

GetHashCode()

取得這個序列點的哈希碼。

適用於