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()

获取此序列点的哈希代码。

适用于