mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-20 07:38:32 +08:00
31 lines
749 B
C#
31 lines
749 B
C#
using Newtonsoft.Json;
|
|
using System.Configuration;
|
|
|
|
namespace Masuit.Tools.Config
|
|
{
|
|
public static class ConfigHelper
|
|
{
|
|
public static string GetConfigOrDefault(string key, string defaultValue = "")
|
|
{
|
|
return ConfigurationManager.AppSettings.Get(key) ?? defaultValue;
|
|
}
|
|
|
|
public static T Get<T>(string key)
|
|
{
|
|
var value = ConfigurationManager.AppSettings.Get(key);
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return default;
|
|
}
|
|
|
|
try
|
|
{
|
|
return JsonConvert.DeserializeObject<T>(value);
|
|
}
|
|
catch
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
}
|
|
} |