Как сериализовать и десериализовать объекты классов?
25.12.2013, 00:05. Показов 1094. Ответов 1
Имеются классы
Pozition.cs
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace PetriNet_v1
{
class Pozition : Element
{
public List<Tranzition> incomingTranzitions;
public List<Tranzition> outcomingTranzitions;
public int CountChips = 0;
public Pozition()
{
incomingTranzitions = new List<Tranzition>();
outcomingTranzitions = new List<Tranzition>();
}
public Pozition(int left, int top)
{
location.X = left;
location.Y = top;
incomingTranzitions = new List<Tranzition>();
outcomingTranzitions = new List<Tranzition>();
}
public void AddIncomingTranzition(Tranzition value, bool recursive)
{
incomingTranzitions.Add(value);
if (recursive)
value.AddOutcomingPozition(this, false);
}
public void AddOutcomingTranzition(Tranzition value, bool recursive)
{
outcomingTranzitions.Add(value);
if (recursive)
value.AddIncomingPozition(this, false);
}
public override void Paint(PictureBox PB)
{
Graphics gr = PB.CreateGraphics();
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gr.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
gr.FillEllipse(Brushes.WhiteSmoke, location.X, location.Y, WIDTH, HEIGTH);
Font font = new Font("Arial", 13);
gr.DrawString(name, font, new SolidBrush(Color.FromArgb(100, 100, 100)), new PointF(location.X + 15, location.Y - 20));
font.Dispose();
font = new Font("Arial", 15);
gr.DrawString(CountChips.ToString(), font, new SolidBrush(Color.FromArgb(100, 100, 100)), new PointF(location.X + (WIDTH - gr.MeasureString(CountChips.ToString(), font).Width) / 2, location.Y + (HEIGTH - gr.MeasureString(CountChips.ToString(), font).Height) / 2));
font.Dispose();
gr.Dispose();
}
}
} |
|
Tranzition.cs
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace PetriNet_v1
{
class Tranzition : Element
{
public List<Pozition> incomingPozitions;
public List<Pozition> outcomingPozitions;
public int Xred =0, Yred=0;
Color color;
public Tranzition()
{
incomingPozitions = new List<Pozition>();
outcomingPozitions = new List<Pozition>();
}
public Tranzition(int left, int top)
{
location.X = left;
location.Y = top;
incomingPozitions = new List<Pozition>();
outcomingPozitions = new List<Pozition>();
}
public void AddIncomingPozition(Pozition value, bool recursive)
{
if (recursive)
value.AddIncomingTranzition(this, false);
incomingPozitions.Add(value);
}
public void AddOutcomingPozition(Pozition value, bool recursive)
{
if (recursive)
value.AddIncomingTranzition(this, false);
outcomingPozitions.Add(value);
}
public override void Paint(PictureBox PB)
{
Graphics gr = PB.CreateGraphics();
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gr.CompositingMode = CompositingMode.SourceOver;
color = Color.Black;
gr.DrawLine(new Pen(color, 5), new Point(location.X+WIDTH / 2, location.Y+HEIGTH), new Point(location.X+WIDTH / 2, location.Y));
gr.DrawString(name, new Font("Arial", 12), new SolidBrush(Color.FromArgb(100, 100, 100)), new PointF(location.X - 7, location.Y - 20));
Pen pen = new Pen(Color.Red, 3);
pen.SetLineCap(LineCap.NoAnchor, LineCap.ArrowAnchor, DashCap.Triangle);
foreach (Pozition p in incomingPozitions)
{
gr.DrawLine(pen,
new Point(p.location.X + Element.WIDTH / 2, p.location.Y + Element.HEIGTH / 2),
new Point(this.location.X + Element.WIDTH / 2, this.location.Y + Element.HEIGTH / 2));
}
pen.Color = Color.Blue;
foreach (Pozition p in outcomingPozitions)
{
gr.DrawLine(pen,
new Point(this.location.X + Element.WIDTH / 2, this.location.Y + Element.HEIGTH / 2),
new Point(p.location.X + Element.WIDTH / 2, p.location.Y + Element.HEIGTH / 2));
}
pen.Dispose();
}
}
} |
|
Как их сериализовать, десериализовать в XML файл
Помогите пожалуйста.. Буду очень признателен..
0
|