/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/VisualStudio/Core/Def/Utilities/ComEventSink.cs
55 строк
2 KB
Cyrus Najmabadi
Remove unnecessary nullable directives
25 мар 2025, 20:43
25 мар 2025, 20:43
1636dd8
Код
Авторство
О чём код?
// 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 Microsoft.VisualStudio.OLE.Interop; namespace Microsoft.VisualStudio.LanguageServices.Implementation; internal sealed class ComEventSink { public static ComEventSink Advise<T>(object obj, T sink) where T : class { if (!typeof(T).IsInterface) { throw new InvalidOperationException(); } if (obj is not IConnectionPointContainer connectionPointContainer) { throw new ArgumentException("Not an IConnectionPointContainer", nameof(obj)); } connectionPointContainer.FindConnectionPoint(typeof(T).GUID, out var connectionPoint); if (connectionPoint == null) { throw new InvalidOperationException("Could not find connection point for " + typeof(T).FullName); } connectionPoint.Advise(sink, out var cookie); return new ComEventSink(connectionPoint, cookie); } private readonly IConnectionPoint _connectionPoint; private readonly uint _cookie; private bool _unadvised; public ComEventSink(IConnectionPoint connectionPoint, uint cookie) { _connectionPoint = connectionPoint; _cookie = cookie; } public void Unadvise() { if (_unadvised) { throw new InvalidOperationException("Already unadvised."); } _connectionPoint.Unadvise(_cookie); _unadvised = true; } }