ConfigurationManager.cs 1.2 KB

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