ServiceProvider.GetService Method (Type)
Assembly: Microsoft.VisualStudio.Shell (in microsoft.visualstudio.shell.dll)
The type of service to retrieve. The GUID of this type is used to obtain the service from the native service provider.
Return ValueThe requested service, or a null reference (Nothing in Visual Basic) if the service could not be located.
Managed VSPackages can use GetService to get Environment SDK COM interfaces by querying the SDK's interop assemblies. For more information, see Interop Namespaces.
To get a specific Environment SDK 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. Aninterface 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 aninterface with:
myUIShell = myPackage.GetService(System.typeof(IVsUIShell)) as IVsUIShell;
For historical reasons, theinterface that cannot be obtained in this manner. To obtain an IVsTextManager interface, first use (the class implementing the interface) as the argument to , then cast the return value of GetService to IVsTextManager, for instance:
IVsTextManager mytext_mgr = myPackage.GetService(System.typeof(VsTextManagerClass)) as IVsTextManager;