ConfigurationHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using WingCloudServer.IpOfflineTools.Model;
  2. namespace WingCloudServer.IpOfflineTools.Service
  3. {
  4. /// <summary>
  5. /// This class will load a glabal server configuration
  6. /// </summary>
  7. public class ConfigurationHelper
  8. {
  9. private static IEnumerable<IParameter> _parameters;
  10. static ConfigurationHelper()
  11. {
  12. var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppSettings.json");
  13. _parameters = ParameterSerializer.Deserialize(configFilePath);
  14. }
  15. /// <summary>
  16. /// Get parameter by specifed section name and parameter name
  17. /// </summary>
  18. /// <typeparam name="T"></typeparam>
  19. public static T GetParammeter<T>(string sectionName, string paramName) where T : class
  20. {
  21. var parameter = _parameters.FirstOrDefault(x => x.Section == sectionName && x.Name == paramName) as T;
  22. if (parameter != null)
  23. {
  24. return parameter;
  25. }
  26. throw new System.ArgumentException($"{sectionName} - {paramName} not set correct");
  27. }
  28. }
  29. }