CodeAttribute2 Interface
TOC
Collapse the table of content
Expand the table of content

CodeAttribute2 Interface

 

Defines an attribute for a code element.

Namespace:   EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

[GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")]
public interface CodeAttribute2 : CodeAttribute

NameDescription
System_CAPS_pubpropertyArguments

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

System_CAPS_pubpropertyChildren

Gets a collection of objects contained within this code construct.

System_CAPS_pubpropertyCollection

Gets a collection of CodeAttribute2 objects.

System_CAPS_pubpropertyDTE

Gets the top-level extensibility object.

System_CAPS_pubpropertyEndPoint

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

System_CAPS_pubpropertyExtender[String]

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

System_CAPS_pubpropertyExtenderCATID

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

System_CAPS_pubpropertyExtenderNames

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

System_CAPS_pubpropertyFullName

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

System_CAPS_pubpropertyInfoLocation

Gets the code model.

System_CAPS_pubpropertyIsCodeType

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

System_CAPS_pubpropertyKind

Gets an enumeration indicating the type of attribute.

System_CAPS_pubpropertyLanguage

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

System_CAPS_pubpropertyName

Sets or gets the name of the code attribute.

System_CAPS_pubpropertyParent

Gets the immediate parent object of the code attribute.

System_CAPS_pubpropertyProjectItem

Gets the ProjectItem associated with the code attribute.

System_CAPS_pubpropertyStartPoint

Gets a TextPoint that defines the beginning of the attribute.

System_CAPS_pubpropertyTarget

Sets or gets the target of the code attribute.

System_CAPS_pubpropertyValue

Sets or gets the data for the code attribute.

NameDescription
System_CAPS_pubmethodAddArgument(String, Object, Object)

Adds an argument to the attribute.

System_CAPS_pubmethodDelete()

Removes all attributes in the code element.

System_CAPS_pubmethodGetEndPoint(vsCMPart)

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

System_CAPS_pubmethodGetStartPoint(vsCMPart)

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

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.

System_CAPS_noteNote

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).

// 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;
}
Return to top
Show:
© 2016 Microsoft