CodeEvent::AddAttribute Method (String^, String^, Object^)
Visual Studio 2015
Creates a new attribute code construct and inserts the code in the correct location.
Assembly: EnvDTE80 (in EnvDTE80.dll)
Parameters
- Name
-
Type:
System::String^
The name of the attribute.
- Value
-
Type:
System::String^
The value of the attribute, which may be a comma separated list of parameters for a parameterized property.
- Position
-
Type:
System::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.
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. |
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"); }
Show:
