Click here to Skip to main content
16,006,432 members
Home / Discussions / C#
   

C#

 
QuestionStatic constructor Pin
Ista20-Jun-06 6:37
Ista20-Jun-06 6:37 
AnswerRe: Static constructor Pin
Le centriste20-Jun-06 8:54
Le centriste20-Jun-06 8:54 
GeneralRe: Static constructor Pin
Ista20-Jun-06 8:55
Ista20-Jun-06 8:55 
GeneralRe: Static constructor Pin
Josh Smith20-Jun-06 9:42
Josh Smith20-Jun-06 9:42 
JokeRe: Static constructor Pin
Le centriste21-Jun-06 8:57
Le centriste21-Jun-06 8:57 
GeneralRe: Static constructor Pin
Josh Smith24-Jun-06 15:37
Josh Smith24-Jun-06 15:37 
QuestionArgh, no matter how long I stare at this, I don't get it (XML Serialization related) [modified] Pin
ThisIsMyUserName220-Jun-06 6:37
ThisIsMyUserName220-Jun-06 6:37 
AnswerRe: Argh, no matter how long I stare at this, I don't get it (XML Serialization related) [modified] Pin
mikanu20-Jun-06 9:09
mikanu20-Jun-06 9:09 
First of all, if you want your data to be serialize to the same file, the easiest way is to put all of your classes in the same container class (i.e. appSettingsMemory). Then it's all a matter of serializing this class to disk. You have to be aware of certain principles of serialization but a quick google search whould put enough light on your problems.

I might publish an article on this subject on my website soon so you may want to check it out at www.digitalGetto.com.

Good Luck

"color: rgba(0, 0, 255, 1)"__^ cXYPosition
	{
		^__b style="color: blue"__^public int</b__^ X;
		^__b style="color: blue"__^public int Y;
	}
	^__b style="color: blue"__^public struct cWindowLocations
	{
		^__b style="color: blue"__^public <font style="color: teal">cXYPosition</font> Main;
		^__b style="color: blue"__^public <font style="color: teal">cXYPosition</font> Options;
	}
	^__b style="color: blue"__^public struct cMenuOptions
	{
		^__b style="color: blue"__^public bool ShowCheckMargin;
		^__b style="color: blue"__^public bool UseXPStyle;
	}
	
	^__b style="color: blue"__^public <font style="color: teal">cWindowLocations</font> WindowLocations;
	^__b style="color: blue"__^public <font style="color: teal">cMeenuOptions</font> MenuOptions;

	^__b style="color: blue"__^public appSettingsMemory()
	{
		^__i__^//initialize all members here
		WindowLocations.Main.X = 0;
		WindowLocations.Main.Y = 0;
		WindowLocations.Options.X = 0;
		WindowLocations.Options.Y = 0;
		MenuOptions.ShowCheckMargin = true;
		MenuOptions.UseXPStyle = false;	
	}
}

^__b style="color: blue"__^public void DumpToFile(<font style="color: teal">appSettinsMemory</font> mem, ^__b style="color: blue"__^string FilePath)
{
    ^__b style="color: blue"__^try
    {
	^__b style="color: blue"__^using (<font style="color: teal">FileStream</font> fs = ^__b style="color: blue"__^new <font style="color: teal">FileStream</font>(FilePath, FileMode.Create))
	{
		<font style="color: teal">XmlSerializer</font> xs = ^__b style="color: blue"__^new <font style="color: teal">XmlSerializer</font>(^__b style="color: blue"__^typeof(<font style="color: teal">appSettingsMemory</font>));
		xs.Serialize(fs, mem);
		fs.Close();
	}
    }
    ^__b style="color: blue"__^catch (<font style="color: teal">Exception</font> e)
    {
	^__i__^//Handle your serialization errors here
	<font style="color: teal">MessageBox</font>.Show(e.Message);
    }
}

^__b style="color: blue"__^public <font style="color: teal">appSettinsMemory</font> LoadFromFile(^__b style="color: blue"__^string FilePath)
{
	<font style="color: teal">appSettingsMemory</font> mem = ^__b style="color: blue"__^new <font style="color: teal">appSettinsMemory</font>();
	^__b style="color: blue"__^try
	{
		^__b style="color: blue"__^using (<font style="color: teal">FileStream</font> fs = ^__b style="color: blue"__^new <font style="color: teal">FileStream</font>(FilePath, FileMode.Open))
		{
			<font style="color: teal">XmlSerializer</font> xs = ^__b style="color: blue"__^new <font style="color: teal">XmlSerializer</font>(^__b style="color: blue">typeof(<font style="color: teal">appSettinsMemory</font>));
                        mem = (<font style="color: teal">appSettinsMemory</font>)xs.Deserialize(fs);
                        fs.Close();
		}
	}
	^__b style="color: blue">catch (<font style="color: teal">Exception</font> e)
	{
		^__i>// Perform any de-serialization error handling here
	}
	^__b style="color: blue">return mem;
}


----
www.digitalGetto.com

-- modified at 15:33 Tuesday 20th June, 2006 (added De-serialization code and color formatting)
GeneralRe: Argh, no matter how long I stare at this, I don't get it (XML Serialization related) [modified] Pin
ThisIsMyUserName220-Jun-06 10:57
ThisIsMyUserName220-Jun-06 10:57 
Questionregain control Pin
donkaiser20-Jun-06 5:59
donkaiser20-Jun-06 5:59 
AnswerRe: regain control Pin
Nicholas Butler20-Jun-06 6:08
sitebuilderNicholas Butler20-Jun-06 6:08 
AnswerRe: regain control Pin
Jun Du20-Jun-06 6:13
Jun Du20-Jun-06 6:13 
GeneralRe: regain control Pin
donkaiser20-Jun-06 6:18
donkaiser20-Jun-06 6:18 
GeneralRe: regain control [modified] Pin
Judah Gabriel Himango20-Jun-06 10:18
sponsorJudah Gabriel Himango20-Jun-06 10:18 
AnswerRe: regain control Pin
darkelv21-Jun-06 0:02
darkelv21-Jun-06 0:02 
QuestionDatagrid with Dataset and Multiple Tables Pin
Leon van Wyk20-Jun-06 5:49
professionalLeon van Wyk20-Jun-06 5:49 
QuestionAutomating Team [modified] Pin
Ista20-Jun-06 5:31
Ista20-Jun-06 5:31 
Questioncode protection for MSIL Pin
yigalef20-Jun-06 5:14
yigalef20-Jun-06 5:14 
AnswerRe: code protection for MSIL Pin
led mike20-Jun-06 5:24
led mike20-Jun-06 5:24 
Questiontimer loop from vb5 Pin
donkaiser20-Jun-06 4:48
donkaiser20-Jun-06 4:48 
AnswerRe: timer loop from vb5 [modified] Pin
led mike20-Jun-06 5:15
led mike20-Jun-06 5:15 
Questiondynamic control Pin
abhaygalande20-Jun-06 4:28
abhaygalande20-Jun-06 4:28 
AnswerRe: dynamic control Pin
Josh Smith20-Jun-06 4:59
Josh Smith20-Jun-06 4:59 
QuestionGet values from a Listview [modified] Pin
Willem_Le_Roux20-Jun-06 3:43
Willem_Le_Roux20-Jun-06 3:43 
AnswerRe: Get values from a Listview Pin
Drew McGhie20-Jun-06 4:19
Drew McGhie20-Jun-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.