File: MathSerialization.cs

package info (click to toggle)
opentk 1.0.20101006%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 38,896 kB
  • ctags: 68,704
  • sloc: cs: 424,330; xml: 96,546; ansic: 3,597; makefile: 24
file content (68 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download
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
#region --- License ---
/* Licensed under the MIT/X11 license.
 * Copyright (c) 2006-2008 the OpenTK team.
 * This notice may not be removed.
 * See license.txt for licensing detailed licensing details.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

#if false

using System.Xml.Serialization;


namespace Examples.Tests
{
    [Example("Serialization", ExampleCategory.Test)]
    public class MathSerialization
    {
        public static void Main()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                XmlSerializer xs = new XmlSerializer(typeof(Matrix4));

                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.NewLineHandling = NewLineHandling.Entitize;
                    settings.Indent = true;
                    XmlWriter xw = XmlTextWriter.Create(stream, settings);

                    xs.Serialize(xw, Matrix4.Identity);

                    xw.Close();
                }

                stream.Position = 0;
                byte[] text = new byte[stream.Length];
                int pos = 0;
                do
                {
                    pos += stream.Read(text, pos, (int)stream.Length);
                }
                while (pos != stream.Length);

                Console.WriteLine(System.Text.Encoding.Default.GetChars(text));

                stream.Position = 0;
                Matrix4 matrix = (Matrix4)xs.Deserialize(stream);

                if (Matrix4.Identity == matrix)
                    Console.WriteLine("Matrix deserialized correctly.");
                else
                    Console.WriteLine("Error deserializing matrix.");

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey(false);
            }
        }
    }
}

#endif