12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Configuration.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Common.Helper
- {
-
-
-
- public class Appsettings
- {
- static IConfiguration Configuration { get; set; }
- static string contentPath { get; set; }
- public Appsettings(string contentPath)
- {
- string Path = "appsettings.json";
-
-
- Configuration = new ConfigurationBuilder()
- .SetBasePath(contentPath)
- .Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true })
- .Build();
- }
- public Appsettings(IConfiguration configuration)
- {
- Configuration = configuration;
- }
-
-
-
-
-
- public static string app(params string[] sections)
- {
- try
- {
- if (sections.Any())
- {
- return Configuration[string.Join(":", sections)];
- }
- }
- catch (Exception) { }
- return "";
- }
-
-
-
-
-
-
- public static List<T> app<T>(params string[] sections)
- {
- List<T> list = new List<T>();
-
- Configuration.Bind(string.Join(":", sections), list);
- return list;
- }
-
-
-
-
-
- public static string GetValue(string sectionsPath)
- {
- try
- {
- return Configuration[sectionsPath];
- }
- catch (Exception) { }
- return "";
- }
- }
- }
|