Package.GetService Method
Gets type-based services from the VSPackage service container.
Namespace: Microsoft.VisualStudio.Shell
Assemblies: Microsoft.VisualStudio.Shell.9.0 (in Microsoft.VisualStudio.Shell.9.0.dll)
Microsoft.VisualStudio.Shell (in Microsoft.VisualStudio.Shell.dll)
Microsoft.VisualStudio.Shell.10.0 (in Microsoft.VisualStudio.Shell.10.0.dll)
Syntax
‘선언
Protected Function GetService ( _
serviceType As Type _
) As Object
‘사용 방법
Dim serviceType As Type
Dim returnValue As Object
returnValue = Me.GetService(serviceType)
protected Object GetService(
Type serviceType
)
protected:
Object^ GetService(
Type^ serviceType
)
member GetService :
serviceType:Type -> Object
protected function GetService(
serviceType : Type
) : Object
Parameters
- serviceType
Type: System.Type
The type of service to retrieve.
Return Value
Type: System.Object
An instance of the requested service, or nulla null reference (Nothing in Visual Basic) if the service could not be found.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | serviceType is nulla null reference (Nothing in Visual Basic). |
Remarks
Managed VSPackages can use GetService to get Environment SDK COM interfaces by querying the interop assemblies of the SDK.
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 searches for on the basis service type GUID with an interface type of IUnknown.
For example, one could get an IVsUIShell interface with:
myUIShell = myPackage.GetService(System.typeof(IVsUIShell)) as IVsUIShell;
참고
For historical reasons, the IVsTextManager interface 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;
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.