1
0

EnvironmentExtensions.cs 608 B

1234567891011121314151617181920
  1. #nullable enable
  2. using System;
  3. using System.Diagnostics.CodeAnalysis;
  4. namespace Content.MapRenderer.Extensions
  5. {
  6. public static class EnvironmentExtensions
  7. {
  8. public static bool TryGetVariable(string key, [NotNullWhen(true)] out string? value)
  9. {
  10. return (value = Environment.GetEnvironmentVariable(key)) != null;
  11. }
  12. public static string GetVariableOrThrow(string key)
  13. {
  14. return Environment.GetEnvironmentVariable(key) ??
  15. throw new ArgumentException($"No environment variable found with key {key}");
  16. }
  17. }
  18. }