Share via


CodeAttribute2 接口

定义代码元素的特性。

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

语法

声明
<GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")> _
Public Interface CodeAttribute2 _
    Inherits CodeAttribute
[GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")]
public interface CodeAttribute2 : CodeAttribute
[GuidAttribute(L"35187E2A-E5F6-4F89-A4CE-DA254640855B")]
public interface class CodeAttribute2 : CodeAttribute
[<GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")>]
type CodeAttribute2 =  
    interface 
        interface CodeAttribute 
    end
public interface CodeAttribute2 extends CodeAttribute

CodeAttribute2 类型公开以下成员。

属性

  名称 说明
公共属性 Arguments 获取一个 CodeElement 对象集合,此集合包含与该特性关联的 CodeAttributeArgument 对象。
公共属性 Children 获取此代码构造中包含的对象的集合。
公共属性 Collection 获取 CodeAttribute2 对象的集合。
公共属性 DTE 获取顶级扩展性对象。
公共属性 EndPoint 获取编辑点,该点是代码特性的结束位置。
公共属性 Extender 如果请求的 Extender 可用于此代码特性,则返回该扩展程序。
公共属性 ExtenderCATID 获取对象的扩展程序类别 ID (CATID)。
公共属性 ExtenderNames 获取此对象的可用扩展程序名称的列表。
公共属性 FullName 获取对象文件的完整路径和名称。
公共属性 InfoLocation 获取代码模型。
公共属性 IsCodeType 获取是否可以从此对象中获取 CodeType 对象。
公共属性 Kind 获取一个指示特性类型的枚举。
公共属性 Language 获取标识用于创作特性的编程语言的常数。
公共属性 Name 设置或获取代码特性的名称。
公共属性 Parent 获取代码特性的直接父对象。
公共属性 ProjectItem 获取与代码特性关联的 ProjectItem
公共属性 StartPoint 获取一个 TextPoint,用于定义特性的开始位置。
公共属性 Target 设置或获取代码特性的目标。
公共属性 Value 设置或获取代码特性的数据。

页首

方法

  名称 说明
公共方法 AddArgument 向特性添加参数。
公共方法 Delete 移除代码元素中的所有特性。
公共方法 GetEndPoint 返回一个 TextPoint 对象,该对象标记特性的结束位置。
公共方法 GetStartPoint 返回一个 TextPoint 对象,该对象定义特性的开始位置。

页首

备注

CodeAttribute2 对象表示一个与代码元素关联的 COM 元数据特性。 您可以通过对适当的对象使用 AddAttribute 方法添加新特性,并通过对适当的对象使用 Delete 方法删除特性。 可以使用该对象获取和设置代码特性的值。

备注

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

示例

// The following example creates a new namespace and attribute in the current class.
public void CreateClassAndAttrib(DTE2 applicationObject)
{
    // Before running, load or create a project.
    FileCodeModel2 fcm2 = GetFileCodeModel(applicationObject);
    CodeAttribute2 cmAttribute;
    CodeClass2 cmClass;

    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);
            }
            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;
}

请参阅

参考

EnvDTE80 命名空间

其他资源

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

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

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