定义代码元素的特性。
命名空间:  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 类型公开以下成员。
属性
页首
方法
| 名称 | 说明 | |
|---|---|---|
| .gif) | AddArgument | 向特性添加参数。 | 
| .gif) | Delete() | (继承自 CodeAttribute。) | 
| .gif) | Delete() | 移除代码元素中的所有特性。 | 
| .gif) | GetEndPoint(vsCMPart) | (继承自 CodeAttribute。) | 
| .gif) | GetEndPoint(vsCMPart) | 返回一个 TextPoint 对象,该对象标记特性的结束位置。 | 
| .gif) | GetStartPoint(vsCMPart) | (继承自 CodeAttribute。) | 
| .gif) | GetStartPoint(vsCMPart) | 返回一个 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;
}
.gif)