Container.GetService(Type) 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得指定型別的服務物件 (如果有的話)。
protected:
virtual System::Object ^ GetService(Type ^ service);
C#
protected virtual object GetService (Type service);
C#
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
實作要求服務的 Object,或 null
(如果無法解析服務)。
如果 service
為 IContainer,這個方法的預設實作會傳回 類別的目前實例,否則會傳 null
回 。 您可以覆寫這個方法,以提供自定義實作以傳回服務物件。 如需詳細資訊,請參閱 IServiceProvider.GetService 方法。
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |