12345678910111213141516171819202122232425262728293031323334353637 |
- using DocTools.Entity.Parameters;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace DocTools.Helper
- {
- /// <summary>
- /// This class will load a glabal server configuration
- /// </summary>
- public class ConfigurationManager
- {
- private static IEnumerable<IParameter> _parameters;
- static ConfigurationManager()
- {
- var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AppSettings.json");
- _parameters = ParameterSerializer.Deserialize(configFilePath);
- }
- /// <summary>
- /// Get parameter by specifed section name and parameter name
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public static T GetParammeter<T>(string sectionName, string paramName) where T : class
- {
- var parameter = _parameters.FirstOrDefault(x => x.Section == sectionName && x.Name == paramName) as T;
- if (parameter != null)
- {
- return parameter;
- }
- throw new System.ArgumentException($"{sectionName} - {paramName} not set correct");
- }
- }
- }
|