CodeAttribute2.EndPoint 属性

获取编辑点,该点是代码特性的结束位置。

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

语法

声明
ReadOnly Property EndPoint As TextPoint
    Get
TextPoint EndPoint { get; }
property TextPoint^ EndPoint {
    TextPoint^ get ();
}
abstract EndPoint : TextPoint
function get EndPoint () : TextPoint

属性值

类型:EnvDTE.TextPoint
返回一个 TextPoint 对象。

实现

CodeAttribute.EndPoint

备注

编辑点位置紧跟在代码特性的最后一个字符(包括任何分号、终止语法或分隔语法)后面。 如果源文件可以打开的话,则隐式提取该属性可打开该源文件。

提示

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

示例

下面的示例在当前类中创建一个新的命名空间和特性,并列出该特性的一些属性。

public void CreateClassAndAttrib(DTE2 applicationObject)
{
    // Before running, load or create a project.
    FileCodeModel2 fcm2 = GetFileCodeModel(applicationObject);
    CodeAttribute2 cmAttribute;
    CodeClass2 cmClass;
    String msg = null;

    if (fcm2 != null)
    {
        CodeNamespace cmNamespace;
        // Try to create a new namespace.
        try
        {
            cmNamespace = fcm2.AddNamespace("CMNamespace", -1);
            // If successful, create the other code elements.
            if (cmNamespace != null)
            {
                cmClass = (CodeClass2)cmNamespace.AddClass("ANewClass", 
                -1, null, null, vsCMAccess.vsCMAccessPrivate);
                cmAttribute = (CodeAttribute2)cmClass.AddAttribute
                ("NewAttribute", "AttributeValue", -1);
                msg += "Arguments: " + cmAttribute.Arguments + 
                Environment.NewLine;
                msg += "Count: " + cmAttribute.Children.Count + 
                Environment.NewLine;
                msg += "Endpoint Location: " + 
                cmAttribute.EndPoint.DisplayColumn + 
                Environment.NewLine;
                MessageBox.Show(msg);                       
            }
            else
            {
                MessageBox.Show("Cannot continue - no filecodemodel 
                available.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex);
        }
    }
}

public FileCodeModel2 GetFileCodeModel(DTE2 applicationObject)
{
    // Returns the FileCodeModel object of the active 
    // window.
    TextWindow txtWin = 
    (TextWindow)applicationObject.ActiveWindow.Object;
    FileCodeModel2 fcm2;
    if (txtWin != null)
    {
        try
        {
             fcm2 = (FileCodeModel2)txtWin.Parent.
             ProjectItem.FileCodeModel;
             return fcm2;
        }
        catch (Exception ex)
        {
             MessageBox.Show("ERROR: " + ex);
             return null;
        }
    }
    else
        return null;
}

.NET Framework 安全性

请参见

参考

CodeAttribute2 接口

EndPoint 重载

EnvDTE80 命名空间

其他资源

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

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

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