/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.Example/ExampleLspServices.cs
60 строк
2 KB
Cyrus Najmabadi
Make sealed
26 мар 2025, 22:21
26 мар 2025, 22:21
d99b771
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.CommonLanguageServerProtocol.Framework.Example; internal sealed class ExampleLspServices : ILspServices { private readonly IServiceProvider _serviceProvider; public ExampleLspServices(IServiceCollection serviceCollection) { _ = serviceCollection.AddSingleton<ILspServices>(this); var serviceProvider = serviceCollection.BuildServiceProvider(); _serviceProvider = serviceProvider; } public T? GetService<T>() where T : notnull { return TryGetService(typeof(T), out var service) ? (T)service : default; } public T GetRequiredService<T>() where T : notnull { var service = _serviceProvider.GetRequiredService<T>(); return service; } public bool TryGetService(Type type, [NotNullWhen(true)] out object? service) { service = _serviceProvider.GetService(type); return service is not null; } public IEnumerable<TService> GetServices<TService>() { return _serviceProvider.GetServices<TService>(); } public void Dispose() { } public IEnumerable<T> GetRequiredServices<T>() { var services = _serviceProvider.GetServices<T>(); return services; } }