// // Copyright (c) jindongfang. All rights reserved. // using SharpConfig; using System.IO; using System.Reflection; using WorkData; namespace WellWorkDataUI { /// /// 配置文件操作类. /// internal static partial class ConfigUtils { /// /// 配置文件路径 /// private static string kFilename => Path.Combine(Config.ProjectPath, "Map", "Config.cfg"); /// /// 属性列表 /// private static PropertyInfo[] kProperties = typeof(ConfigUtils).GetProperties(BindingFlags.Static | BindingFlags.Public); /// /// 加载属性. /// public static void Load() { LoadFrom(kFilename); } /// /// 保存属性. /// public static void Save() { SaveTo(kFilename); } /// /// 从其他文件加载配置. /// /// The filename. public static void LoadFrom(string filename) { if (File.Exists(filename)) { var cfg = Configuration.LoadFromFile(filename); foreach (var item in kProperties) { item.SetValue(null, cfg[item.PropertyType.Name].ToObject(item.PropertyType)); } } } /// /// 另存配置文件. /// /// The filename. public static void SaveTo(string filename) { var cfg = new Configuration(); foreach (var item in kProperties) { cfg.Add(Section.FromObject(item.PropertyType.Name, item.GetValue(null))); } cfg.SaveToFile(filename); } } /// /// 配置文件操作类. /// internal partial class ConfigUtils { /// /// Gets the general data. /// /// The general data. public static Interpret InterpretData { get; private set; } = new Interpret(); /// /// Interpret设置. /// public class Interpret { /// /// 查看模式. /// /// The view mode. public ViewMode ViewMode { get; set; } = ViewMode.Data; } } /// /// 查看模式 /// public enum ViewMode { /// /// 显示数据 /// Data = 0x01, /// /// 显示图表 /// Chart = 0x02, /// /// 全部显示 /// Both = Data | Chart, } }