Пример #1
0
 public static void SaveToFile(string file, FileSaving config)
 {
     lock (_lock)
     {
         var xns = new System.Xml.Serialization.XmlSerializerNamespaces();
         System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(config.GetType());
         System.IO.Stream stream;
         if (config.GetType().Name != "opencv_storage")
         {
             stream = new System.IO.MemoryStream();
         }
         else
         {
             System.IO.File.WriteAllText(file, "");
             stream = System.IO.File.OpenWrite(file);
         }
         xns.Add(string.Empty, string.Empty);
         x.Serialize(stream, config, xns);
         if (config.GetType().Name != "opencv_storage")
         {
             stream.Position = 0;
             byte[] bs = new byte[stream.Length];
             ((System.IO.MemoryStream)stream).Read(bs, 0, bs.Length);
             string s = xmlHeader + "<opencv_storage>" + System.Text.Encoding.UTF8.GetString(bs).Replace(xmlHeader, "") + "</opencv_storage>";
             System.IO.File.WriteAllText(file, s);
         }
         stream.Close();
     }
 }
Пример #2
0
 public virtual void Save()
 {
     FileSaving.SaveToFile(fileName, this);
 }