ServiceProvider.GetService ServiceProvider.GetService ServiceProvider.GetService ServiceProvider.GetService ServiceProvider.GetService Method

Definition

Gets GUID-based services from the unmanaged service provider.

Overloads

GetService(Guid) GetService(Guid) GetService(Guid)

Gets the specified service from the unmanaged service provider.

GetService(Type) GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Gets type-based services from the unmanaged service provider.

Remarks

Services are identified for retrieval by an associated GUID. ServiceProvider allows services to be requested directly with a GUID, but is overloaded to permit requests by service type as well.

GetService(Guid) GetService(Guid) GetService(Guid)

Gets the specified service from the unmanaged service provider.

public:
 System::Object ^ GetService(Guid guid);
public object GetService (Guid guid);
member this.GetService : Guid -> obj
Parameters
guid
Guid Guid Guid Guid Guid

The GUID of the service to retrieve.

Returns

The requested service, or null if the service could not be located.

GetService(Type) GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Gets type-based services from the unmanaged service provider.

public:
 virtual System::Object ^ GetService(Type ^ serviceType);
public:
 Platform::Object ^ GetService(Platform::Type ^ serviceType);
public object GetService (Type serviceType);
abstract member GetService : Type -> obj
override this.GetService : Type -> obj
Public Function GetService (serviceType As Type) As Object
Parameters
serviceType
Type Type Type Type Type

The type of service to retrieve. The GUID of this type is used to obtain the service from the native service provider.

Returns

The requested service, or null if the service could not be located.

Remarks

Managed VSPackages can use GetService to get VSSDK COM interfaces by querying the interop assemblies. For more information, see Interop Namespaces.

To get a specific VSSDK interface:

  • GetService should be called with a serviceType returned by using that interface as an argument to typeof.

  • The return value of GetService must be cast to the interface type. The casting is necessary because GetService queries the input type for the GUID of the service that provides it. An IUnknown interface on the class implementing the service is then returned, and must be cast to obtain the desired object. (The object must be supported on the underlying service.)

    For example, one could get an IVsUIShell interface with:

    myUIShell = myPackage.GetService(System.typeof(IVsUIShell)) as IVsUIShell;  
    

Note

For historical reasons, the IVsTextManager interface that cannot be obtained in this manner. To obtain an IVsTextManager interface, first use VsTextManagerClass (the class implementing the interface) as the argument to typeof, then cast the return value of GetService to IVsTextManager, for instance:

IVsTextManager mytext_mgr = myPackage.GetService(System.typeof(VsTextManagerClass)) as IVsTextManager;

Applies to