Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My app contains options that user can set and the options are applied to app when it is launced.

 

What is standard way to do this?

My guess are using App configuration xml file, using Window registry or etc.

 

If you have any code example please post it.

Thank you all.

Sun Certified Web component Developer,

Microsoft Certified Solution Developer .NET,

Software Engineer

Posted

I think the best way would be for you to use Xml Serialization to write an xml file with all your settings. Heres an example:

 

Make a class with all your options in it:

 

public class Options

{

public string opt1;

public int opt2;

public string opt3;

}

 

Then create some functions that will serialize and deserialize the info:

 

public static void Serialize(Options Prefs)

{

//create xml serializer

XmlSerializer Serializer = new XmlSerializer(typeof(Options));

//create writer

StreamWriter Writer = new StreamWriter(Path);

//serialize Data in the options class with the writer

Serializer.Serialize(Writer, Prefs);

//close the writer

Writer.Close();

}

 

 

 

public static Options Deserialize()

{

//create xml serializer

XmlSerializer Serializer = new XmlSerializer(typeof(Options));

//create reader

StreamReader Reader = new StreamReader(Path);

//deserialize the xml and load it into the Prefs variable

Options Prefs = (Options)Serializer.Deserialize(Reader);

//close the reader

Reader.Close();

//return the Options

return Prefs;

}

 

Tell me if you need me to explain a little better. :)

 

 

Dan

  • 1 month later...
Posted

Hi I have a question one this serialization example. Could the above sample be easily modified to handle multiple objects that have been serialized? I know conceptually it dosn't work in this case, as there would only ever be one "options" object per project, but for the sake of the exercise could this be done. The serialization isde is ok, I guess you'd just dupe the "Serializer.Serialize(Writer, Prefs);" line per object. What about when deserializing? How do you specify the object to deserialize?

 

Thanks a heap! SEVI

Posted

Updated Example

 

I'm sorry, the link I posted was incorrect. Now I can't seem to find the proper article.

 

However, I still have the source download from the article, which also includes a copy of it in a Word document. I have attached it here.

vbUserSettings.zip

mov ax, 13h

int 10h

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...