mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
combine website examples.
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置管理器
|
||||
/// </summary>
|
||||
public static class AppSettingsManager
|
||||
{
|
||||
private static IConfiguration _configuration;
|
||||
|
||||
static AppSettingsManager()
|
||||
{
|
||||
BuildConfiguration();
|
||||
}
|
||||
|
||||
private static void BuildConfiguration()
|
||||
{
|
||||
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", false).AddJsonFile("appsettings.Development.json", true);
|
||||
_configuration = builder.Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取指定节点信息
|
||||
/// </summary>
|
||||
/// <param name="key">节点名称,多节点以:分隔</param>
|
||||
public static string Get(string key)
|
||||
{
|
||||
return _configuration[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取指定节点信息
|
||||
/// </summary>
|
||||
public static T Get<T>(string key)
|
||||
{
|
||||
string json = Get(key);
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
}
|
||||
}
|
37
Examples/website/FreeSql.Site.DAL/Helper/EnumHelper.cs
Normal file
37
Examples/website/FreeSql.Site.DAL/Helper/EnumHelper.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Site.DAL.Helper
|
||||
{
|
||||
public class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举类型转换为字符串
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="en"></param>
|
||||
/// <returns></returns>
|
||||
public static string EnumConvertToString<T>(T en)
|
||||
{
|
||||
//方法一
|
||||
//return color.ToString();
|
||||
|
||||
//方法二
|
||||
return Enum.GetName(en.GetType(), en);
|
||||
}
|
||||
public static T StringConvertToEnum<T>(string str)
|
||||
{
|
||||
T result = default(T);
|
||||
try
|
||||
{
|
||||
result = (T)Enum.Parse(typeof(T), str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user