Skip to content

Instantly share code, notes, and snippets.

@georgepaoli
Last active March 21, 2024 13:02
Show Gist options
  • Save georgepaoli/55fe5994f6ad061241ef47ac21908042 to your computer and use it in GitHub Desktop.
Save georgepaoli/55fe5994f6ad061241ef47ac21908042 to your computer and use it in GitHub Desktop.
EnvHelper - Helper to read variables in .env file using C#
public static class EnvHelper
{
public static string ENV_VAR_A => GetEnvVar();
public static string ENV_VAR_B => GetEnvVar();
public static string ENV_VAR_C => GetEnvVar();
private static string GetEnvVar([CallerMemberName] string name = null)
=> Environment.GetEnvironmentVariable(name);
}
/* content .env file
ENV_VAR_A=value A
ENV_VAR_B=value B
ENV_VAR_C=value C
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment