Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

how to save my class in settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ryan Germain - 13 Mar 2008 20:29 GMT
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; }
       }
   }
Ryan Germain - 14 Mar 2008 22:39 GMT
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?

> 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
[quoted text clipped - 99 lines]
>        }
>    }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.