EnvironmentsOptionsExtensions.cs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. namespace Unity.Services.Core.Environments
  3. {
  4. /// <summary>
  5. /// Initialization option extensions related to environments.
  6. /// </summary>
  7. public static class EnvironmentsOptionsExtensions
  8. {
  9. internal const string EnvironmentNameKey = "com.unity.services.core.environment-name";
  10. /// <summary>
  11. /// An extension to set the environment to use.
  12. /// </summary>
  13. /// <param name="self">The InitializationOptions object to modify</param>
  14. /// <param name="environmentName">The name of the environment to use</param>
  15. /// <exception cref="ArgumentException">Throws a <see cref="ArgumentException"/> if environmentName is null or empty.</exception>
  16. /// <returns>
  17. /// Return <paramref name="self"/>.
  18. /// Fluent interface pattern to make it easier to chain set options operations.
  19. /// </returns>
  20. public static InitializationOptions SetEnvironmentName(this InitializationOptions self, string environmentName)
  21. {
  22. if (string.IsNullOrEmpty(environmentName))
  23. throw new ArgumentException("Environment name cannot be null or empty.", nameof(environmentName));
  24. self.SetOption(EnvironmentNameKey, environmentName);
  25. return self;
  26. }
  27. }
  28. }