c# 使用 静态类+xml序列化 保存配置文件
namespace TVCorrectionDataProcess
{
[XmlRoot(ElementName = "Config")]
public class ConfigData
{
[XmlElement("SrcFileDirectory")]
public String srcFileDirectory{ get; set; }
[XmlElement("DesFileDirectory")]
public String desFileDirectory{ get; set; }
public ConfigData()
{
}
}
public static class Config
{
public static ConfigData configdata = new ConfigData();
public static String configFilePath = Plugin.Path + "\\Config.xml";
private static void ReadConfigFile(String sFile)
{
XmlSerializer ser = new XmlSerializer(typeof(ConfigData));
configdata = (ConfigData)ser.Deserialize(File.OpenRead(sFile));
}
private static void WriteConfigFile(String sFile)
{
XmlSerializer ser = new XmlSerializer(typeof(ConfigData));
FileStream fs = File.Create(sFile);
ser.Serialize(fs, configdata);
fs.Close();
}
public static void ReadConfigFile()
{
ReadConfigFile(configFilePath);
}
public static void WriteConfigFile()
{
WriteConfigFile(configFilePath);
}
}