Concord(VS调试器)方法链接问题

Concord (VS debugger) method chaining question

我试图理解方法链(调用以前的或默认的实现)是如何工作的(https://github.com/Microsoft/ConcordExtensibilitySamples/wiki/Component-discovery-and-configuration),但仍有很多疑问。

提前致谢

Method Chaining Example中,IDkmExample代表一个接口,是ConcordAPI的一部分。这是您作为开发人员正在实现的接口。在方法调用本身中,DkmExample 不是 dispatcher,而是调度程序知道如何处理的 dispatcher object。这些由调度程序定义,不能在外部定义。

方法链接示例显示如果实现不想处理接口方法的调用,那么它可以调用 dispatcher object 上的同名方法(第一项API 方法签名),传入方法签名减去调度程序对象本身所采用的所有参数。这将允许调度程序根据过滤和优先级将调用传递给它可以找到的接口的下一个实现。

具体的例子,我们可以看看microsoft.visualstudio.debugger.engine nuget包中的Microsoft.VisualStudio.Debugger.Engine.xml中的以下块:

<member name="M:Microsoft.VisualStudio.Debugger.ComponentInterfaces.IDkmStartDebuggingOperations.LaunchDebuggedProcess(Microsoft.VisualStudio.Debugger.Start.DkmProcessLaunchRequest)">
    <summary>
    Causes the debug monitor to create a new process under the debugger. The process
    should be left suspended until ResumeDebuggedProcess is called. The debug monitor
    must wait for ResumeDebuggedProcess before creating the DkmProcess object since
    it needs the UniqueProcessId value from the AD7 Layer.

    Note that this method may only be called in response to the Visual Studio
    debugger package requesting a launch. Components that wish to launch another
    process under the debugger should send a custom event to a visual studio package.
    From a package, a launch can be requested through the
    IVsDebugger.LaunchDebugTargets API.
    </summary>
    <param name="request">
    [In] DkmProcessLaunchRequest is used to describe the process that debugger should
    launch.
    </param>
    <returns>
    [Out] DkmLaunchedProcessInfo is returned from APIs that launch a process.
    </returns>
</member>

我们覆盖的接口是 IDkmStartDebuggingOperations,方法是 LaunchDebuggedProcess,在实现中将采用 DkmProcessLaunchRequest,即 dispatcher object。如果实现不想处理调用,它可以通过获取 dispatcher object 并在其上调用同名方法并传递必要的参数来调用下一个实现。

例如:

internal class MyStartDebuggingOperations : IDkmStartDebuggingOperations
{
    public DkmLaunchedProcessInfo LaunchDebuggedProcess(DkmProcessLaunchRequest request)
    {
        if (/* custom check that this class is to handle it */)
        {
            // Handle custom implementation here
        }
        else
        {
            // This calls the base implementation
            return request.LaunchDebuggedProcess();
        }
    }
}