CodeEvent.AddAttribute(String, String, Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建新的特性代码构造,并将代码插入正确的位置。
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
参数
- Name
- String
属性名。
- Value
- String
特性的值,该值可以是由逗号分隔的参数化属性的参数列表。
返回
CodeAttribute 对象。
- 属性
示例
下面的示例演示如何使用 AddAttribute 方法。
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");
}
注解
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。