how to save my class in settings

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; }
}
}
 
R

Ryan Germain

Also, SyncSystem is in a ClassLibrairy Project seperate from the project
where I am trying to save the settings but in the same solution.

Also, if I fill the ArrayList filled with a string instead of the SyncSystem
class, everything is honky dorey and works great. So I assume it is
something with my class not being serializable...but why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top