ContextAttributes.Add(String, String, vsContextAttributeType) 方法

定义

将特性名称/值对添加到 ContextAttributes 集合中。

public:
 EnvDTE::ContextAttribute ^ Add(System::String ^ AttributeName, System::String ^ AttributeValue, EnvDTE::vsContextAttributeType Type);
public:
 EnvDTE::ContextAttribute ^ Add(Platform::String ^ AttributeName, Platform::String ^ AttributeValue, EnvDTE::vsContextAttributeType Type);
EnvDTE::ContextAttribute Add(std::wstring const & AttributeName, std::wstring const & AttributeValue, EnvDTE::vsContextAttributeType Type);
[System.Runtime.InteropServices.DispId(4)]
public EnvDTE.ContextAttribute Add (string AttributeName, string AttributeValue, EnvDTE.vsContextAttributeType Type);
[<System.Runtime.InteropServices.DispId(4)>]
abstract member Add : string * string * EnvDTE.vsContextAttributeType -> EnvDTE.ContextAttribute
Public Function Add (AttributeName As String, AttributeValue As String, Type As vsContextAttributeType) As ContextAttribute

参数

AttributeName
String

必需。 新特性的名称。

AttributeValue
String

必需。 新特性的值。

Type
vsContextAttributeType

必需。 vsContextAttributeType指定新属性的类型的常量。

返回

ContextAttribute

ContextAttribute 对象。

属性

示例

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  

注解

Add 允许您 (上下文包) 或创建关键字向集合添加新属性。

备注

如果在其上调用方法的集合对象已 Type 设置为 vsContextAttributesGlobal ,则此方法将失败 E_NOTIMPL

适用于