Regarding the XmlSerializer's Deserialize

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have the following code.
When there is no virtualConfig.xml, the _hotKeys would have 3 items.
But after the config file is created, I have to Deserialize from the xml file. But its strange that the _hotKeys would have 6 items. How is the unnecessary items created?

[Serializable]
public class ApplicationSettings
{
private static List<long> _hotKeys;
public ApplicationSettings()
{

_hotKeys = new List<long>();
_hotKeys.Add((long)HotKeyCommand.Play * 10000 + (long)HotKey.ModifiedKeys.MOD_ALT * 1000 + (long)System.Windows.Forms.Keys.U);
_hotKeys.Add((long)HotKeyCommand.Stop * 10000 + (long)HotKey.ModifiedKeys.MOD_ALT * 1000 + (long)System.Windows.Forms.Keys.S);
_hotKeys.Add((long)HotKeyCommand.Snap * 10000 + (long)HotKey.ModifiedKeys.MOD_ALT * 1000 + (long)System.Windows.Forms.Keys.N);

}

public static ApplicationSettings Load()
{
try
{
XmlSerializer xs = new XmlSerializer(typeof(ApplicationSettings));
Stream stream = new FileStream(ApplicationSettings.AppDataFolder + @"VirtualConfig.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
ApplicationSettings p = xs.Deserialize(stream) as ApplicationSettings;
stream.Close();
return p;
}
catch (Exception)
{

}
return null;

}

public void Save()
{
XmlSerializer xs = new XmlSerializer(typeof(ApplicationSettings));
Stream stream = new FileStream(ApplicationSettings.AppDataFolder + @"VirtualCameraConfig.xml", FileMode.Create, FileAccess.Write, FileShare.Read);
xs.Serialize(stream, _instance);
stream.Close();
}


}
<hr class="sig video edit

View the full article
 
Back
Top