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 / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

User defined types in application settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Tallman - 14 Feb 2006 00:19 GMT
Is there a way to store an object of a user defined type in the applications
settings?

I have compiled the type in a dll and referenced the dll into my
application.
I have applied the [Serializable] attribute to my user defined type.
I can create a settings property of the correct type, but it won't serialize
(or won't deserialize).

Example:

public class State
{
   bool b1;
   string s1;
   int n1;

   public State(bool b, string s, int n)
   {
       b1=b; s1=s; n1=1;
   }
}

public void TestStateSetting()
{
   Settings.Default.MyState = new State(true, "Hi", 0);
   Settings.Default.MyString = "System.string serializes ok";

   // Save and reload settings to simulate program shutdown and restart.
   Settings.Default.Save();
   Settings.Default.Reload();

   // Primitive types work but user defined (and other system types) don't
work.
   MessageBox.Show("Settings.Default.MyState == null !!");
   MessageBox.Show("Settings.Default.MyString == 'System.string serializes
ok'");
}
Otis Mukinfus - 14 Feb 2006 04:32 GMT
>Is there a way to store an object of a user defined type in the applications
>settings?
[quoted text clipped - 34 lines]
>ok'");
>}

Tony,

It might be easier to just Serialize the class and write it to a file
using binary serialization.

I believe if you search the help for SerializableAttribute you will
find a description of the attribute and some sample code to get you
started.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Otis Mukinfus - 14 Feb 2006 04:34 GMT
>Is there a way to store an object of a user defined type in the applications
>settings?
[quoted text clipped - 34 lines]
>ok'");
>}

Oops!  I see you've already found the attribute...

I still would serialize it to a binary file, though...

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

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.