CodeEvent.AddAttribute(String, String, Object) Method

Definition

Creates a new attribute code construct and inserts the code in the correct location.

EnvDTE::CodeAttribute AddAttribute(std::wstring const & Name, std::wstring const & Value, winrt::Windows::Foundation::IInspectable const & Position);
[System.Runtime.InteropServices.DispId(36)]
public EnvDTE.CodeAttribute AddAttribute (string Name, string Value, object Position);
[<System.Runtime.InteropServices.DispId(36)>]
abstract member AddAttribute : string * string * obj -> EnvDTE.CodeAttribute
Public Function AddAttribute (Name As String, Value As String, Optional Position As Object) As CodeAttribute

Parameters

Name
String

The name of the attribute.

Value
String

The value of the attribute, which may be a comma separated list of parameters for a parameterized property.

Position
Object

Optional. The position of the element after which to add the new element.

If the value is zero, the new element is added at the beginning of the collection (default); if the value is -1, at the end.

Returns

A CodeAttribute object.

Attributes

Examples

The following example demonstrates how to use the AddAttribute method.

public static void AddAttribute(EnvDTE80.DTE2 dte)  
{  
    TextSelection objTextSel;  
    EnvDTE80.CodeEvent codeEvent;  
    objTextSel = (TextSelection)dte.ActiveDocument.Selection;  
    codeEvent = (EnvDTE80.CodeEvent)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementEvent);  

    codeEvent.AddAttribute("Obsolete", "\"NewAttribute\", true", 1);  
    string str = "";  
    foreach (CodeElement ce in codeEvent.Attributes)  
        str += "\n" + ce.FullName;  
    MessageBox.Show("\nAddAttribute method: " +  
                    str, "Testing CodeEvent");  
}  

Remarks

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.

Applies to