/// <summary> /// 写配置对象到xml文件 /// </summary> /// <param name="config">配置对象</param> /// <param name="configFilePath">配置文件存放路径</param> public static void WriteConfigToXmlFile(object config, string configFilePath) { if (configFilePath == null) { throw new ArgumentNullException(nameof(configFilePath)); } XDocument xdoc = WriteConfigToXDocument(config); DirectoryInfoEx.CheckFilePathDirectory(configFilePath); xdoc.Save(configFilePath); }
private void SaveCurrentColumnsSetting() { try { var columnSettingFilePath = this._getColSettingFilePath(); if (string.IsNullOrWhiteSpace(columnSettingFilePath)) { return; } DirectoryInfoEx.CheckFilePathDirectory(columnSettingFilePath); var xdoc = new XDocument(); var rootEle = new XElement("DGVColumnsLayout"); rootEle.Add(new XAttribute("Count", this._dgv.Columns.Count)); foreach (DataGridViewColumn col in this._dgv.Columns) { var itemEle = new XElement("Item"); itemEle.Add(new XAttribute("Name", col.Name)); itemEle.Add(new XAttribute("Width", col.Width)); itemEle.Add(new XAttribute("DisplayIndex", col.DisplayIndex)); itemEle.Add(new XAttribute("Visible", col.Visible)); rootEle.Add(itemEle); } xdoc.Add(rootEle); string dir = Path.GetDirectoryName(columnSettingFilePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } xdoc.Save(columnSettingFilePath); } catch (IOException ioex) { MessageBox.Show(ioex.Message); Loger.Error(ioex); } catch (Exception ex) { Loger.Error(ex); } }
private static void SerializeToFile(object config, string configFilePath) { GeneratConfigFilePath(config.GetType(), ref configFilePath); DirectoryInfoEx.CheckFilePathDirectory(configFilePath); WriteConfigToXmlFile(config, configFilePath); }