CodeAttribute2 Interface

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Defines an attribute for a code element.

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

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

The CodeAttribute2 type exposes the following members.

  NameDescription
Public propertyArgumentsGets a collection of CodeElement objects that contains the CodeAttributeArgument objects associated with this attribute.
Public propertyChildrenGets a collection of objects contained within this code construct.
Public propertyCollectionGets a collection of CodeAttribute2 objects.
Public propertyDTEGets the top-level extensibility object.
Public propertyEndPointGets the edit point that is the end location of the code attribute.
Public propertyExtenderReturns the requested Extender if it is available for this code attribute.
Public propertyExtenderCATIDGets the Extender category ID (CATID) for the object.
Public propertyExtenderNamesGets a list of names of available Extenders for the object.
Public propertyFullNameGets the full path and name of the object's file.
Public propertyInfoLocationGets the code model.
Public propertyIsCodeTypeGets whether a CodeType object can be obtained from this object.
Public propertyKindGets an enumeration indicating the type of attribute.
Public propertyLanguageGets a constant identifying the programming language used to author the attribute.
Public propertyNameSets or gets the name of the code attribute.
Public propertyParentGets the immediate parent object of the code attribute.
Public propertyProjectItemGets the ProjectItem associated with the code attribute.
Public propertyStartPointGets a TextPoint that defines the beginning of the attribute.
Public propertyTargetSets or gets the target of the code attribute.
Public propertyValueSets or gets the data for the code attribute.
Top

  NameDescription
Public methodAddArgumentAdds an argument to the attribute.
Public methodDeleteRemoves all attributes in the code element.
Public methodGetEndPointReturns a TextPoint object that marks the end position of the attribute.
Public methodGetStartPointReturns a TextPoint object that defines the beginning position of the attribute.
Top

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.

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;
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft