/// <summary> /// 設定ファイル書き込み /// </summary> static void ConfigWrite() { ApplicationConfig config = new ApplicationConfig(); MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ApplicationConfig)); ser.WriteObject(stream1, config); stream1.Position = 0; StreamReader sr = new StreamReader(stream1); StreamWriter writer = new StreamWriter("config.json", false, Encoding.UTF8); writer.WriteLine(sr.ReadToEnd()); writer.Close(); }
/// <summary> /// 設定ファイル読み込み /// </summary> public void ConfigRead() { using (StreamReader reader = new StreamReader("config.json", Encoding.UTF8)) { string text = reader.ReadToEnd(); reader.Close(); using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(text))) { stream.Position = 0; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ApplicationConfig)); this.config = (ApplicationConfig)ser.ReadObject(stream); } } }