WorkflowView.GetService(Type) 方法

定义

获取指定类型的服务对象(如果可用)。Gets the service object of the specified type, if it is available.

protected:
 override System::Object ^ GetService(Type ^ serviceType);
protected override object GetService (Type serviceType);
override this.GetService : Type -> obj
Protected Overrides Function GetService (serviceType As Type) As Object

参数

serviceType
Type

要检索的服务的 TypeThe Type of the service to retrieve.

返回

Object

如果 serviceTypetypeof(CommandID),则 GetService 返回特定的 CommandID;否则,GetService 返回实现所请求服务的 Object,或在无法解析服务的情况下返回空引用(在 Visual Basic 中为 Nothing)。If the serviceType is typeof(CommandID) then GetService returns a specific CommandID; otherwise, GetService returns a Object implementing the requested service, or a null reference (Nothing in Visual Basic) if the service cannot be resolved.

示例

下面的示例使用 GetService 对象的 WorkflowView 方法返回 ISelectionService 接口。The following example uses the GetService method of the WorkflowView object to return an ISelectionService interface. 如果服务存在,则使用 EnsureVisible 对象的 PrimarySelection 属性调用 ISelectionService 传递当前选择的活动。If the service exists, EnsureVisible is called passing the currently selected activity using the PrimarySelection property of the ISelectionService object.

public void FindSelection()
{
    ISelectionService selectionService;
    selectionService = ((IServiceProvider)this.workflowView).GetService(typeof(ISelectionService))
        as ISelectionService;

    if (selectionService != null)
        this.workflowView.EnsureVisible(selectionService.PrimarySelection);
}
Public Sub FindSelection()
    Dim selectionService As ISelectionService
    selectionService = CType(CType(Me.workflowView, IServiceProvider).GetService(GetType(ISelectionService)), ISelectionService)

    If selectionService IsNot Nothing Then
        Me.workflowView.EnsureVisible(selectionService.PrimarySelection)
    End If
End Sub

注解

GetService 返回实现所请求服务的 Object,或在无法解析服务的情况下返回空引用 (Nothing)。GetService returns a Object implementing the requested service, or a null reference (Nothing) if the service cannot be resolved.

适用于