ConfigurationCollectionHelper.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Unity.Services.Core.Internal;
  5. using UnityEngine;
  6. namespace Unity.Services.Core.Configuration
  7. {
  8. static class ConfigurationCollectionHelper
  9. {
  10. public static void FillWith(
  11. this IDictionary<string, ConfigurationEntry> self, SerializableProjectConfiguration config)
  12. {
  13. for (var i = 0; i < config.Keys.Length; i++)
  14. {
  15. var entryKey = config.Keys[i];
  16. var entryValue = config.Values[i];
  17. self.SetOrCreateEntry(entryKey, entryValue);
  18. }
  19. }
  20. public static void FillWith(
  21. this IDictionary<string, ConfigurationEntry> self, InitializationOptions options)
  22. {
  23. foreach (var option in options.Values)
  24. {
  25. var optionValue = Convert.ToString(option.Value, CultureInfo.InvariantCulture);
  26. self.SetOrCreateEntry(option.Key, optionValue);
  27. }
  28. }
  29. static void SetOrCreateEntry(
  30. this IDictionary<string, ConfigurationEntry> self, string key, ConfigurationEntry entry)
  31. {
  32. if (self.TryGetValue(key, out var existingEntry))
  33. {
  34. if (!existingEntry.TrySetValue(entry))
  35. {
  36. CoreLogger.LogWarning(
  37. $"You are attempting to initialize Operate Solution SDK with an option \"{key}\"" +
  38. " which is readonly at runtime and can be modified only through Project Settings." +
  39. " The value provided as initialization option will be ignored." +
  40. $" Please update {nameof(InitializationOptions)} in order to remove this warning.");
  41. }
  42. }
  43. else
  44. {
  45. self[key] = entry;
  46. }
  47. }
  48. }
  49. }