扩展我之前的问题,我决定(de)序列化我的配置文件类,它运行得很好.
我现在想存储驱动器盘符映射关联数组(关键是驱动器号,值是网络路径)和使用都试过Dictionary,HybridDictionary和Hashtable打电话时的这一点,但我总是得到下面的错误ConfigFile.Load()或者ConfigFile.Save():
反映类型'App.ConfigFile'时出错.[snip] System.NotSupportedException:无法序列化成员App.Configfile.mappedDrives [snip]
从我读过的词典和HashTables可以被序列化,所以我做错了什么?
[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 …Run Code Online (Sandbox Code Playgroud)