Container.GetService(Type) 方法

定義

取得指定型別的服務物件 (如果有的話)。Gets the service object of the specified type, if it is available.

protected:
 virtual System::Object ^ GetService(Type ^ service);
protected virtual object GetService (Type service);
abstract member GetService : Type -> obj
override this.GetService : Type -> obj
Protected Overridable Function GetService (service As Type) As Object

參數

service
Type

要擷取之服務的 TypeThe Type of the service to retrieve.

傳回

實作要求服務的 Object,或 null (如果無法解析服務)。An Object implementing the requested service, or null if the service cannot be resolved.

備註

如果 serviceIContainer,這個方法的預設執行會傳回類別的目前實例。否則,它會傳回 nullThe default implementation of this method returns the current instance of the class if service is an IContainer; otherwise, it returns null. 您可以覆寫這個方法,以提供自訂的執行方式來傳回服務物件。You can override this method to provide a custom implementation to return a service object. 如需詳細資訊,請參閱 IServiceProvider.GetService 方法。For more information, see the IServiceProvider.GetService method.

適用於

另請參閱