openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Utility/AppContextSwitchHelper.cs

33lines · modeblame

d5b5c604Liudmila Molkova1 years ago1using System;
2
3namespace OpenAI;
4
5internal static class AppContextSwitchHelper
6{
7/// <summary>
8/// Determines if either an AppContext switch or its corresponding Environment Variable is set
9/// </summary>
8a376a68大師兄丶1 years ago10/// <param name="appContextSwitchName">Name of the AppContext switch.</param>
d5b5c604Liudmila Molkova1 years ago11/// <param name="environmentVariableName">Name of the Environment variable.</param>
12/// <returns>If the AppContext switch has been set, returns the value of the switch.
13/// If the AppContext switch has not been set, returns the value of the environment variable.
14/// False if neither is set.
15/// </returns>
8a376a68大師兄丶1 years ago16public static bool GetConfigValue(string appContextSwitchName, string environmentVariableName)
d5b5c604Liudmila Molkova1 years ago17{
18// First check for the AppContext switch, giving it priority over the environment variable.
8a376a68大師兄丶1 years ago19if (AppContext.TryGetSwitch(appContextSwitchName, out bool value))
d5b5c604Liudmila Molkova1 years ago20{
21return value;
22}
23// AppContext switch wasn't used. Check the environment variable.
24string envVar = Environment.GetEnvironmentVariable(environmentVariableName);
25if (envVar != null && (envVar.Equals("true", StringComparison.OrdinalIgnoreCase) || envVar.Equals("1")))
26{
27return true;
28}
29
30// Default to false.
31return false;
32}
33}