/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/VisualStudio/Core/Def/Options/FeatureFlagPersister.cs
63 строки
2 KB
Tomáš Matoušek
Add Microsoft.CodeAnalysis.Contracts source package (#76997)
11 фев 2025, 21:45
Не верифицирован
11 фев 2025, 21:45
eeff8ea
Код
Авторство
О чём код?
// 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.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Options; using Microsoft.Internal.VisualStudio.Shell.Interop; namespace Microsoft.VisualStudio.LanguageServices.Options; internal sealed class FeatureFlagPersister { private readonly IVsFeatureFlags? _featureFlags; public FeatureFlagPersister(IVsFeatureFlags? featureFlags) { _featureFlags = featureFlags; } public bool TryFetch(OptionKey2 optionKey, string flagName, [NotNullWhen(true)] out object? value) { if (_featureFlags == null) { value = null; return false; } if (optionKey.Option.DefaultValue is not bool defaultValue) { throw ExceptionUtilities.UnexpectedValue(optionKey.Option.DefaultValue); } try { value = _featureFlags.IsFeatureEnabled(flagName, defaultValue); } catch (Exception e) when (FatalError.ReportAndCatch(e)) { value = defaultValue; } return true; } public void Persist(string flagName, object? value) { if (value is not bool flag) { throw ExceptionUtilities.UnexpectedValue(value); } try { ((IVsFeatureFlags2?)_featureFlags)?.EnableFeatureFlag(flagName, flag); } catch (Exception e) when (FatalError.ReportAndCatch(e)) { } } }