Add Method
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

ContextAttributes.Add Method

Adds an attribute name/value pair to the ContextAttributes collection.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

ContextAttribute Add (
	string AttributeName,
	string AttributeValue,
	vsContextAttributeType Type
)
ContextAttribute Add (
	String AttributeName, 
	String AttributeValue, 
	vsContextAttributeType Type
)
function Add (
	AttributeName : String, 
	AttributeValue : String, 
	Type : vsContextAttributeType
) : ContextAttribute

Parameters

AttributeName

Required. The name of the new attribute.

AttributeValue

Required. The value of the new attribute.

Type

Required. A vsContextAttributeType constant specifying the type of new attribute.

Return Value

A ContextAttribute object.

Add allows you to add a new attribute to the collection (context bag) or create keywords.

NoteNote

If the collection object on which you are calling the method has Type set to vsContextAttributesGlobal, then this method fails with E_NOTIMPL.

Sub AddExample()
   ' Get a reference to Solution Explorer.
   Dim SolnEx As Window = DTE.Windows.Item _
   (Constants.vsWindowKindSolutionExplorer)
   Dim CA As ContextAttribute

   ' List the current attributes associated with Solution Explorer.
   ListAttr(SolnEx, CA)

   ' Associate a new F1 keyword with Solution Explorer.
   SolnEx.ContextAttributes.Add("ANewKeyword", 900, _
   vsContextAttributeType.vsContextAttributeLookupF1)
   ListAttr(SolnEx, CA)

   ' Delete the new F1 keyword from Solution Explorer.
   SolnEx.ContextAttributes.Item(3).Remove()
   ListAttr(SolnEx, CA)
End Sub

Sub ListAttr(ByVal SolnEx As Object, ByVal CA As ContextAttribute)
   ' Support function for CATest(). Lists the current attributes 
   ' associated with Solution Explorer.
   Dim msg As String

   MsgBox("Number of context attributes in Solution Explorer: " & _
   SolnEx.ContextAttributes.Count)
   For Each CA In SolnEx.ContextAttributes
      msg = msg & CA.Name & Chr(13)
   Next
   MsgBox(msg)
   msg = ""
End Sub
Show:
© 2016 Microsoft