Partilhar via


CodeAttribute2 Interface

Definition

Defines an attribute for a code element.

public interface class CodeAttribute2 : EnvDTE::CodeAttribute
public interface class CodeAttribute2 : EnvDTE::CodeAttribute
__interface CodeAttribute2 : EnvDTE::CodeAttribute
[System.Runtime.InteropServices.Guid("35187E2A-E5F6-4F89-A4CE-DA254640855B")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface CodeAttribute2 : EnvDTE.CodeAttribute
[<System.Runtime.InteropServices.Guid("35187E2A-E5F6-4F89-A4CE-DA254640855B")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type CodeAttribute2 = interface
    interface CodeAttribute
Public Interface CodeAttribute2
Implements CodeAttribute
Attributes
Implements

Examples

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

Remarks

The CodeAttribute2 object represents a single COM metadata attribute associated with a code element. You can add new attributes with the AddAttribute method, and delete the attributes by using the Delete method on the appropriate object. You can get and set the value of a code attribute by using this object.

Note

The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

Properties

Arguments

Gets a collection of CodeElement objects that contains the CodeAttributeArgument objects associated with this attribute.

Children

Gets a collection of objects contained within this code construct.

Collection

Gets a collection of CodeAttribute2 objects.

DTE

Gets the top-level extensibility object.

EndPoint

Gets the edit point that is the end location of the code attribute.

Extender[String]

Returns the requested Extender if it is available for this code attribute.

ExtenderCATID

Gets the Extender category ID (CATID) for the object.

ExtenderNames

Gets a list of names of available Extenders for the object.

FullName

Gets the full path and name of the object's file.

InfoLocation

Gets the code model.

IsCodeType

Gets whether a CodeType object can be obtained from this object.

Kind

Gets an enumeration indicating the type of attribute.

Language

Gets a constant identifying the programming language used to author the attribute.

Name

Sets or gets the name of the code attribute.

Parent

Gets the immediate parent object of the code attribute.

ProjectItem

Gets the ProjectItem associated with the code attribute.

StartPoint

Gets a TextPoint that defines the beginning of the attribute.

Target

Sets or gets the target of the code attribute.

Value

Sets or gets the data for the code attribute.

Methods

AddArgument(String, Object, Object)

Adds an argument to the attribute.

Delete()

Removes all attributes in the code element.

GetEndPoint(vsCMPart)

Returns a TextPoint object that marks the end position of the attribute.

GetStartPoint(vsCMPart)

Returns a TextPoint object that defines the beginning position of the attribute.

Applies to