序列化包含字典成员的类
Dictionary
, HybridDictionary
Hashtable
ConfigFile.Load()
ConfigFile.Save()
:
反映类型‘App.ConfigFile’时出错。[Snip]System.NotSupportdException:无法序列化成员App.Configfile.mempdDrives[Snip]
[XmlRoot(ElementName="Config")]public class ConfigFile{ public String guiPath { get; set; } public string configPath { get; set; } public Dictionary<string, string> mappedDrives = new Dictionary<string, string>(); public Boolean Save(String filename) { using(var filestream = File.Open(filename, FileMode.OpenOrCreate,FileAccess.ReadWrite)) { try { var serializer = new XmlSerializer(typeof(ConfigFile)); serializer.Serialize(filestream, this); return true; } catch(Exception e) { MessageBox.Show(e.Message); return false; } } } public void addDrive(string drvLetter, string path) { this.mappedDrives.Add(drvLetter, path); } public static ConfigFile Load(string filename) { using (var filestream = File.Open(filename, FileMode.Open, FileAccess.Read)) { try { var serializer = new XmlSerializer(typeof(ConfigFile)); return (ConfigFile)serializer.Deserialize(filestream); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.ToString()); return new ConfigFile(); } } }}
相关分类