1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using System.Runtime.Serialization.Formatters.Binary;
6
7 namespace WinFormTest
8 {
9 [Serializable]
10 public class Class1:ICloneable
11 {
12 private string _t1;
13 private string _t2;
14 private Class2 _c2;
15
16 public string T1
17 {
18 get
19 {
20 return _t1;
21 }
22 set
23 {
24 _t1 = value;
25 }
26 }
27
28
29 public string T2
30 {
31 get
32 {
33 return DateTime.Now.ToString();
34 }
35
36 }
37
38 public Class2 C2
39 {
40 get
41 {
42 return _c2;
43 }
44 set
45 {
46 _c2 = value;
47 }
48 }
49
50 public Object Clone()
51 {
52 {
53 MemoryStream stream = new MemoryStream();
54 BinaryFormatter formatter = new BinaryFormatter();
55 formatter.Serialize(stream, this);
56 stream.Position = 0;
57
58 return formatter.Deserialize(stream);
59 }
60 }
61
62 }
63 }
64
2 using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using System.Runtime.Serialization.Formatters.Binary;
6
7 namespace WinFormTest
8 {
9 [Serializable]
10 public class Class1:ICloneable
11 {
12 private string _t1;
13 private string _t2;
14 private Class2 _c2;
15
16 public string T1
17 {
18 get
19 {
20 return _t1;
21 }
22 set
23 {
24 _t1 = value;
25 }
26 }
27
28
29 public string T2
30 {
31 get
32 {
33 return DateTime.Now.ToString();
34 }
35
36 }
37
38 public Class2 C2
39 {
40 get
41 {
42 return _c2;
43 }
44 set
45 {
46 _c2 = value;
47 }
48 }
49
50 public Object Clone()
51 {
52 {
53 MemoryStream stream = new MemoryStream();
54 BinaryFormatter formatter = new BinaryFormatter();
55 formatter.Serialize(stream, this);
56 stream.Position = 0;
57
58 return formatter.Deserialize(stream);
59 }
60 }
61
62 }
63 }
64