- C#, can't serialize to binary
- [Serializable]
- public class Settings : ISerializable
- {
- public static string server= "http://localhost/";
- public static string username = "myname";
- public static bool savePassword = true;
- public static bool autoSync = true;
- public static string password = "mypass";
- public static string folderPath1= "c:/";
- public static string folderPath2= "c:/";
- public static string autoSyncDuration = "300";
- public static string lastSyncTime = "???";
- public Settings()
- { }
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- Type myTypeObj = Type.GetType("Settings");
- foreach (FieldInfo p in myTypeObj.GetFields())
- {
- Object value = p.GetValue(null);
- info.AddValue(p.Name, value, p.GetType());
- }
- }
- public Settings(SerializationInfo info, StreamingContext context)
- {
- Type myTypeObj = Type.GetType("Settings");
- FieldInfo p;
- foreach (SerializationEntry e in info)
- {
- p = myTypeObj.GetField(e.Name);
- p.SetValue(null, e.Value);
- }
- }
- }
- private void writeSettings()
- {
- pcb_savingSettings.Visible = true;
- FileStream fileStream = new FileStream(settingFile, FileMode.Create, FileAccess.Write, FileShare.None);
- BinaryFormatter bf = new BinaryFormatter();
- bf.Serialize(fileStream, new Settings());
- fileStream.Close();
- pcb_savingSettings.Visible = false;
- }
- private void readSettings()
- {
- if (!File.Exists(settingFile))
- {
- writeSettings();
- }
- FileStream fileStream = new FileStream(settingFile, FileMode.Open, FileAccess.Read, FileShare.None);
- BinaryFormatter bf = new BinaryFormatter();
- bf.Deserialize(fileStream);
- fileStream.Close();
- }
- bf.Deserialize(fileStream);
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- Type myTypeObj = Type.GetType("Settings");
- foreach (FieldInfo p in myTypeObj.GetFields())
- {
- Object value = p.GetValue(null);
- info.AddValue(p.Name, value, p.GetType());
- }
- }
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- Type myTypeObj = Type.GetType("Settings");
- foreach (FieldInfo p in myTypeObj.GetFields())
- {
- Object value = p.GetValue(null);
- info.AddValue(p.Name, value, value.GetType());
- }
- }