-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathNuGetFeatureFlags.cs
More file actions
35 lines (29 loc) · 1.61 KB
/
NuGetFeatureFlags.cs
File metadata and controls
35 lines (29 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.CodeAnalysis;
using NuGet.Common;
namespace NuGet.Shared
{
internal static class NuGetFeatureFlags
{
internal const string UseNSJDeserializationSwitchName = "NuGet.UseNSJDeserialization";
internal const string UseNSJDeserializationEnvVar = "NUGET_USE_NSJ_DESERIALIZATION";
private static readonly Lazy<bool> _isNSJDeserializationEnabledByEnvironment =
new Lazy<bool>(() => IsNSJDeserializationEnabledByEnvironment(EnvironmentVariableWrapper.Instance));
/// <summary>Feature switch for NSJ deserialization. Defaults to <see langword="false"/> (STJ is the default).</summary>
[FeatureSwitchDefinition(UseNSJDeserializationSwitchName)]
internal static bool UseNSJDeserializationFeatureSwitch { get; } =
AppContext.TryGetSwitch(UseNSJDeserializationSwitchName, out bool value) && value;
/// <summary>Returns <see langword="true"/> when env var <c>NUGET_USE_NSJ_DESERIALIZATION</c> is <c>true</c>.</summary>
internal static bool IsNSJDeserializationEnabledByEnvironment(IEnvironmentVariableReader? env = null)
{
if (env is null)
{
return _isNSJDeserializationEnabledByEnvironment.Value;
}
string? envValue = env.GetEnvironmentVariable(UseNSJDeserializationEnvVar);
return string.Equals(envValue, "true", StringComparison.OrdinalIgnoreCase);
}
}
}