Click here to Skip to main content
15,888,330 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# audio file Pin
lenator24-Aug-06 3:35
lenator24-Aug-06 3:35 
AnswerRe: C# audio file Pin
Mohammad Hajjat24-Aug-06 4:24
Mohammad Hajjat24-Aug-06 4:24 
QuestionReg Treeview Pin
Shiv524-Aug-06 0:44
Shiv524-Aug-06 0:44 
AnswerRe: Reg Treeview Pin
Malcolm Smart24-Aug-06 1:35
Malcolm Smart24-Aug-06 1:35 
QuestionUnsubscribing all event listeners Pin
sjembek24-Aug-06 0:38
sjembek24-Aug-06 0:38 
QuestionRe: Unsubscribing all event listeners Pin
beatles169224-Aug-06 6:04
beatles169224-Aug-06 6:04 
AnswerRe: Unsubscribing all event listeners [modified] Pin
sjembek24-Aug-06 23:44
sjembek24-Aug-06 23:44 
GeneralRe: Unsubscribing all event listeners Pin
beatles169225-Aug-06 2:56
beatles169225-Aug-06 2:56 
Hi This case can be an example of memento design pattern.Using this pattern you can save state of your objects in another object(a memento) and then you can put you object back to its initial state.
for example:
<br />
public class Test<br />
{<br />
private int x;<br />
public EventHandler XChanged;<br />
<br />
public int X<br />
{<br />
get{return x;}<br />
set<br />
{<br />
this.x=value;<br />
if(this.XChanged!=null) XChanged(this,EventArgs.Empty);<br />
}<br />
<br />
public TestMemento GetMemento()<br />
{<br />
TestMemento memento=new TestMemento();<br />
memento.AddField("x",this.x");<br />
}<br />
<br />
public void SetMemento(TestMemento memento)<br />
{<br />
this.x=(int)memento.GetField("x");<br />
}<br />
<br />
}<br />


and here is TestMemento
<br />
public class TestMemento<br />
{<br />
public void AddField(string key,object value)<br />
{<br />
this.fieldsMap.Add(key,value); //fieldsMap is a hashtable<br />
}<br />
public object GetField(string key)<br />
{<br />
return this.fieldsMap[key];<br />
}<br />
}<br />


this way you can save an object state and load it again.
Take a look at serialization patterns in C# and .Net framework.
Regards
GeneralRe: Unsubscribing all event listeners [modified] Pin
sjembek25-Aug-06 4:09
sjembek25-Aug-06 4:09 
GeneralRe: Unsubscribing all event listeners Pin
beatles169225-Aug-06 12:16
beatles169225-Aug-06 12:16 
QuestionC# and SQL server problem Pin
William Ten Broek23-Aug-06 23:49
William Ten Broek23-Aug-06 23:49 
QuestionRe: C# and SQL server problem Pin
CooperWu24-Aug-06 0:42
CooperWu24-Aug-06 0:42 
AnswerRe: C# and SQL server problem Pin
William Ten Broek24-Aug-06 11:27
William Ten Broek24-Aug-06 11:27 
GeneralRe: C# and SQL server problem [modified] Pin
CooperWu24-Aug-06 16:34
CooperWu24-Aug-06 16:34 
AnswerRe: C# and SQL server problem Pin
~~~Johnny~~~24-Aug-06 1:47
~~~Johnny~~~24-Aug-06 1:47 
Questionint to String conversion Pin
Brendan Vogt23-Aug-06 23:49
Brendan Vogt23-Aug-06 23:49 
AnswerRe: int to String conversion Pin
William Ten Broek23-Aug-06 23:55
William Ten Broek23-Aug-06 23:55 
AnswerRe: int to String conversion Pin
CooperWu23-Aug-06 23:59
CooperWu23-Aug-06 23:59 
AnswerRe: int to String conversion Pin
ayyp24-Aug-06 0:30
ayyp24-Aug-06 0:30 
AnswerRe: int to String conversion Pin
Guffa24-Aug-06 2:50
Guffa24-Aug-06 2:50 
GeneralRe: int to String conversion Pin
Brendan Vogt24-Aug-06 3:31
Brendan Vogt24-Aug-06 3:31 
GeneralRe: int to String conversion Pin
Guffa24-Aug-06 12:20
Guffa24-Aug-06 12:20 
GeneralRe: int to String conversion Pin
Brendan Vogt24-Aug-06 22:37
Brendan Vogt24-Aug-06 22:37 
AnswerRe: int to String conversion Pin
Guffa25-Aug-06 9:31
Guffa25-Aug-06 9:31 
GeneralRe: int to String conversion Pin
Brendan Vogt27-Aug-06 20:34
Brendan Vogt27-Aug-06 20:34 

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.