IVsaCodeItem.AddEventSource(String, String) 方法

定义

将事件源添加到代码项中。Adds an event source to the code item. 代码项通过调用 IVsaSite.GetEventSourceInstance 方法(由宿主实现),使用事件源将事件挂钩到命名事件源。The code item uses the event source to hook up an event to the named event source by calling the IVsaSite.GetEventSourceInstance method, which is implemented by the host.

public:
 void AddEventSource(System::String ^ eventSourceName, System::String ^ eventSourceType);
public void AddEventSource (string eventSourceName, string eventSourceType);
abstract member AddEventSource : string * string -> unit
Public Sub AddEventSource (eventSourceName As String, eventSourceType As String)

参数

eventSourceName
String

事件源的编程名称。A programmatic name of the event source.

eventSourceType
String

事件源的类型名称。The type name of the event source.

注解

脚本引擎使用 AddEventSource 方法提供的信息将事件挂钩到命名事件源。The script engine uses information provided by the AddEventSource method to hook up events to the named event source. 它通过调用由主机实现的 (由. Ivsasite.geteventsourceinstance 方法获取事件源。It obtains event sources by calling the IVsaSite.GetEventSourceInstance method, which is implemented by the host. AddEventSource 方法创建一个类,用于处理由宿主提供的对象引发的事件。The AddEventSource method creates a class that handles events raised by a host-provided object.

备注

JScript .NET 脚本引擎不支持此方法。The JScript .NET script engine does not support this method. 如果 JScript .NET 引擎必须挂钩某个事件,则必须使用全局项来执行此操作。In cases where the JScript .NET engine must hook up an event, you must do so using a global item. JScript .NET 引擎使用 AppGlobal 项类型,而不是事件源。Rather than event sources, the JScript .NET engine uses AppGlobal item types. 有关详细信息,请参阅 VsaItemType。For more information, see VsaItemType.

在代码项中,你可以按名称访问事件源对象,并可在访问后针对对象编写事件处理程序。Within the code item, you can access the event source object by name, and, once accessed, you can write event handlers against the object. 事件源类型作为字符串(而不是类型对象)传递,以方便非托管主机实现事件源。The event source type is passed as a string rather than as a Type object to facilitate implementing event sources by unmanaged hosts.

编译器使用 eventSourceType 参数绑定到类型所提供的方法。The compiler uses the eventSourceType parameter to bind to methods provided by the type. 稍后在脚本引擎调用 (由. Ivsasite.geteventsourceinstance 方法请求类型对象的实例时,也会使用此方法。It is also used later when the script engine calls the IVsaSite.GetEventSourceInstance method to request an instance of the Type object.

有关为脚本引擎挂接事件的机制的详细信息,请参阅 (由. Ivsasite.geteventsourceinstance 方法。For more information about the mechanisms for hooking up events for the script engine, see the IVsaSite.GetEventSourceInstance method.

适用于