Line | |
---|
1 | Namespace SerializeTest
|
---|
2 |
|
---|
3 |
|
---|
4 | Class Foo
|
---|
5 | Public
|
---|
6 | a As Long
|
---|
7 | b As Long
|
---|
8 | c As Long
|
---|
9 | d As Long
|
---|
10 |
|
---|
11 | Sub Foo()
|
---|
12 | a=100
|
---|
13 | b=200
|
---|
14 | c=300
|
---|
15 | d=400
|
---|
16 | End Sub
|
---|
17 | End Class
|
---|
18 |
|
---|
19 | Sub TestMain()
|
---|
20 | ' 一時ディレクトリを取得
|
---|
21 | Dim tempDir = GetExclusiveTempDirPath( "SerializeTest" )
|
---|
22 |
|
---|
23 | ' fooインスタンスを生成
|
---|
24 | Dim foo = New Foo
|
---|
25 | foo.a = 500
|
---|
26 | foo.b = 600
|
---|
27 | foo.c = 700
|
---|
28 | foo.d = 800
|
---|
29 |
|
---|
30 |
|
---|
31 | '----------------------------------------------------------------
|
---|
32 | ' シリアライズ
|
---|
33 | '----------------------------------------------------------------
|
---|
34 |
|
---|
35 | ' 保存先のファイルを開いて、
|
---|
36 | Dim fooXmlFilePath = tempDir + "\foo.xml"
|
---|
37 | Dim ofs = New System.IO.FileStream( fooXmlFilePath, System.IO.FileMode.Create )
|
---|
38 |
|
---|
39 | ' シリアライズして、
|
---|
40 | Dim serializer = New System.Xml.Serialization.XmlSerializer( foo.GetType() )
|
---|
41 | serializer.Serialize( ofs, foo )
|
---|
42 |
|
---|
43 | ' 閉じる。
|
---|
44 | ofs.Close()
|
---|
45 |
|
---|
46 |
|
---|
47 | '----------------------------------------------------------------
|
---|
48 | ' デシリアライズ
|
---|
49 | '----------------------------------------------------------------
|
---|
50 |
|
---|
51 | ' 読込先のファイルを開いて
|
---|
52 | Dim ifs = New System.IO.FileStream( fooXmlFilePath, System.IO.FileMode.Open )
|
---|
53 |
|
---|
54 | ' デシリアライズして
|
---|
55 | Dim fooDash = serializer.Deserialize( ifs ) As Foo
|
---|
56 |
|
---|
57 | ' 閉じる
|
---|
58 | ifs.Close()
|
---|
59 |
|
---|
60 | UnitTest( "XmlSerializer", foo.a = fooDash.a and foo.b = fooDash.b and foo.c = fooDash.c and foo.d = fooDash.d )
|
---|
61 | End Sub
|
---|
62 |
|
---|
63 |
|
---|
64 | End Namespace
|
---|
65 |
|
---|
66 | SerializeTest.TestMain()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.