/// <summary> /// 写配置 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="path"></param> public static void Write <T>(T t, string path) { try { path = FPS.Combine(path); Serializer serializer = new Serializer(); StringWriter strWriter = new StringWriter(); serializer.Serialize(strWriter, t); serializer.Serialize(Console.Out, t); using (TextWriter writer = File.CreateText(path)) writer.Write(strWriter.ToString()); } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// 读配置 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <returns></returns> public static T Read <T>(string path) { path = FPS.Combine(path); T t = default; try { Deserializer deserializer = new Deserializer(); if (FPS.CheckFile(path, FpsModel.Default)) { using (TextReader reader = File.OpenText(path)) t = deserializer.Deserialize <T>(reader); } } catch (Exception e) { MessageBox.Show(e.Message); } return(t); }