CodeClass2.AddEvent(String, String, Boolean, Object, vsCMAccess) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
添加一个类事件。
EnvDTE80::CodeEvent AddEvent(std::wstring const & Name, std::wstring const & FullDelegateName, bool CreatePropertyStyleEvent = false, winrt::Windows::Foundation::IInspectable const & Location, EnvDTE::vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault);
[System.Runtime.InteropServices.DispId(209)]
public EnvDTE80.CodeEvent AddEvent (string Name, string FullDelegateName, bool CreatePropertyStyleEvent = false, object Location, EnvDTE.vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault);
[<System.Runtime.InteropServices.DispId(209)>]
abstract member AddEvent : string * string * bool * obj * EnvDTE.vsCMAccess -> EnvDTE80.CodeEvent
Public Function AddEvent (Name As String, FullDelegateName As String, Optional CreatePropertyStyleEvent As Boolean = false, Optional Location As Object, Optional Access As vsCMAccess = EnvDTE.vsCMAccess.vsCMAccessDefault) As CodeEvent
参数
- Name
- String
必需。 要添加的类事件的名称。
- FullDelegateName
- String
必需。 事件要基于的委托的名称。 它用作新事件处理程序的模板。
- CreatePropertyStyleEvent
- Boolean
可选。 创建具有属性样式访问器的事件。 True 指示事件应具有访问器, false 指示它不应为。
- Location
- Object
- Access
- vsCMAccess
可选。 一个 vsCMAccess 常数。
返回
返回创建的类事件处理程序。
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。
- 属性
示例
[Visual Basic]
Sub AddEventExample(ByVal dte As DTE2)
' Before running this example, open a code document from a project
' and place the insertion point inside a class definition.
Try
' Retrieve the CodeClass at the insertion point.
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim cls As CodeClass = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementClass), CodeClass)
' Create a new event handler.
cls.AddEvent("NewOnConnection", "OnConnection", True, -1,
vsCMAccess.vsCMAccessPublic)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
[C#]
public void AddEventExample(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point inside a class definition.
try
{
// Retrieve the CodeClass at the insertion point.
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
CodeClass cls =
(CodeClass)sel.ActivePoint.get_CodeElement(
vsCMElement.vsCMElementClass);
// Creates a new event handler.
cls.AddEvent("NewOnConnection", "OnConnection", true, -1,
vsCMAccess.vsCMAccessPublic);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}