CodeClass2.GetEndPoint 方法

获取一个 TextPoint 对象,该对象标记类的结束位置。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
Function GetEndPoint ( _
    Part As vsCMPart _
) As TextPoint
TextPoint GetEndPoint(
    vsCMPart Part
)
TextPoint^ GetEndPoint(
    [InAttribute] vsCMPart Part
)
abstract GetEndPoint : 
        Part:vsCMPart -> TextPoint
function GetEndPoint(
    Part : vsCMPart
) : TextPoint

参数

  • Part
    类型:vsCMPart

    可选。 一个 vsCMPart 常数,该常数指定要检索的类部分。

返回值

类型:TextPoint
一个 TextPoint 对象。

备注

GetStartPoint 和 GetEndPoint 方法返回一个 TextPoint 对象,该对象表示指定的代码元素定义的开始和结束位置。 Part 参数定义要返回的代码元素定义。

备注

在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。

示例

[Visual Basic]

Sub GetEndPointExample(ByVal dte As DTE2)
    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a class definition.
    Try
        ' Retrieve the CodeClass at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim cls As CodeClass = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementClass), CodeClass)

        ' Get the source code for the class.
        Dim start As TextPoint = cls.GetStartPoint()
        Dim finish As TextPoint = cls.GetEndPoint()
        Dim src As String = start.CreateEditPoint().GetText(finish)

        MsgBox(cls.Name & "'s source code:" & vbCrLf & vbCrLf & src)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

[C#]

public void GetEndPointExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a class definition.
    try
    {
        // Retrieve the CodeClass at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeClass cls = 
            (CodeClass)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Get the source code for the class.
        TextPoint start = cls.GetStartPoint(vsCMPart.vsCMPartWhole);
        TextPoint finish = cls.GetEndPoint(vsCMPart.vsCMPartWhole);
        string src = start.CreateEditPoint().GetText(finish);

        MessageBox.Show(cls.Name + "'s source code:" + 
            Environment.NewLine + Environment.NewLine + src);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

请参阅

参考

CodeClass2 接口

EnvDTE80 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)