R
Ryan Germain
I'm trying to use the settings class of my C# project to save an ArrayList
of my class SyncSystem. I have added the ArrayList using the settings
dialog with user scope. What happens is that when I save the settings,
everything works great. But when I close the application then start it up
again, the saved data is no longer there, the ArrayList is null. I check
this by adding this to fMain:
if (SFS.Properties.Settings.Default.SyncSystems == null)
{
MessageBox.Show("null");
SFS.Properties.Settings.Default.SyncSystems = new
System.Collections.ArrayList();
}
What am I doing wrong? Is my class not serializable? An ArrayList is
serializable, right?
here is the save code:
SyncSystem ss = new SyncSystem();
ss.name = tbName.Text;
ss.source = comboDir.Text;
ss.destination = comboDir.Text;
ss.recurse = chkRecurse.Checked;
ss.mode = SyncSystem.syncMode.echo;
SFS.Properties.Settings.Default.SyncSystems.Add(ss);
SFS.Properties.Settings.Default.Save(); // doesnt save
after program closed
foreach (SyncSystem s in
SFS.Properties.Settings.Default.SyncSystems)
MessageBox.Show(s.name);
here is the class:
public class SyncSystem
{
public enum syncMode
{
echo,
equalize,
mirror
}
private string _name;
private string _source;
private string _destination;
private syncMode _mode;
private bool _recurse;
public SyncSystem()
{
_name = "";
_source = "";
_destination = "";
_recurse = false;
_mode = syncMode.mirror;
}
public SyncSystem(string name,
string source,
string destination,
bool recurse,
syncMode mode)
{
_name = name;
_source = source;
_destination = destination;
_recurse = recurse;
_mode = mode;
}
public string name
{
get{ return _name; }
set{ _name = value; }
}
public string source
{
get { return _source; }
set { _source = value; }
}
public string destination
{
get { return _destination; }
set { _destination = value; }
}
public bool recurse
{
get { return _recurse; }
set { _recurse = value; }
}
public syncMode mode
{
get { return _mode; }
set { _mode = value; }
}
}
of my class SyncSystem. I have added the ArrayList using the settings
dialog with user scope. What happens is that when I save the settings,
everything works great. But when I close the application then start it up
again, the saved data is no longer there, the ArrayList is null. I check
this by adding this to fMain:
if (SFS.Properties.Settings.Default.SyncSystems == null)
{
MessageBox.Show("null");
SFS.Properties.Settings.Default.SyncSystems = new
System.Collections.ArrayList();
}
What am I doing wrong? Is my class not serializable? An ArrayList is
serializable, right?
here is the save code:
SyncSystem ss = new SyncSystem();
ss.name = tbName.Text;
ss.source = comboDir.Text;
ss.destination = comboDir.Text;
ss.recurse = chkRecurse.Checked;
ss.mode = SyncSystem.syncMode.echo;
SFS.Properties.Settings.Default.SyncSystems.Add(ss);
SFS.Properties.Settings.Default.Save(); // doesnt save
after program closed
foreach (SyncSystem s in
SFS.Properties.Settings.Default.SyncSystems)
MessageBox.Show(s.name);
here is the class:
public class SyncSystem
{
public enum syncMode
{
echo,
equalize,
mirror
}
private string _name;
private string _source;
private string _destination;
private syncMode _mode;
private bool _recurse;
public SyncSystem()
{
_name = "";
_source = "";
_destination = "";
_recurse = false;
_mode = syncMode.mirror;
}
public SyncSystem(string name,
string source,
string destination,
bool recurse,
syncMode mode)
{
_name = name;
_source = source;
_destination = destination;
_recurse = recurse;
_mode = mode;
}
public string name
{
get{ return _name; }
set{ _name = value; }
}
public string source
{
get { return _source; }
set { _source = value; }
}
public string destination
{
get { return _destination; }
set { _destination = value; }
}
public bool recurse
{
get { return _recurse; }
set { _recurse = value; }
}
public syncMode mode
{
get { return _mode; }
set { _mode = value; }
}
}