private void SaveResource(string filename, StringResource resource) { XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.IndentChars = " "; setting.NewLineOnAttributes = true; setting.OmitXmlDeclaration = true; try { filename = AppDomain.CurrentDomain.BaseDirectory + @"config\Language\" + filename + ".xml"; FileStream fs = new FileStream(filename, FileMode.Create); XmlWriter xw = XmlWriter.Create(fs, setting); XmlSerializer xs = new XmlSerializer(resource.GetType()); xs.Serialize(xw, resource); } catch { } }
private void Load(string resourceName, out StringResource obj) { obj = new StringResource(); string filename = AppDomain.CurrentDomain.BaseDirectory + @"config\Language\" + resourceName + ".xml"; if (File.Exists(filename) == false) return; FileStream fs = new FileStream(filename, FileMode.Open); XmlReader sr = XmlReader.Create(fs); XmlSerializer xs = new XmlSerializer(obj.GetType()); obj = (StringResource)xs.Deserialize(sr); }