Files
29WxOrder/Source/MAX.Framework/Configs/ConfigBase.cs
T
2026-08-31 16:28:23 +08:00

47 lines
823 B
C#

using Newtonsoft.Json;
using ConfigHelper = MAX.Framework.Helpers.ConfigHelper;
namespace MAX.Framework.Configs
{
public abstract class ConfigBase
{
[JsonIgnore]
public abstract string ConfigName { get; }
}
/// <summary>
/// 设置
/// </summary>
public abstract class ConfigBase<TConfig> : ConfigBase where TConfig : ConfigBase, new()
{
private static TConfig mySelf;//= default(T);
public static TConfig Instance
{
get
{
if (mySelf == null)
{
mySelf = new TConfig();
}
return mySelf;
}
}
public static TConfig LoadConfig()
{
try
{
TConfig config = ConfigHelper.LoadConfig<TConfig>();
mySelf = config;
return mySelf;
}
catch { }
return default;
}
public void SaveConfig()
{
ConfigHelper.SaveConfig(ConfigName, this);
}
}
}