[corlib] Fix a few NSLogWriter issues. (#13799)
[mono-project.git] / mcs / tests / gtest-186.cs
blobc45f99b7e83040ef90fb37d3d1ab5b04d7a11191
1 using System;
2 using System.IO;
3 using System.Runtime.Serialization;
4 using System.Runtime.Serialization.Formatters.Binary;
6 [Serializable]
7 public class Tuple <a,b> {
8 public a field1;
9 public b field2;
11 public Tuple (a x, b y) {
12 field1 = x;
13 field2 = y;
18 public class Test {
19 public static void Main() {
21 //Creates a new TestSimpleObject object.
22 TestSimpleObject obj = new TestSimpleObject();
24 Console.WriteLine("Before serialization the object contains: ");
25 obj.Print();
27 //Opens a file and serializes the object into it in binary format.
28 Stream stream = File.Open("data.xml", FileMode.Create);
29 BinaryFormatter formatter = new BinaryFormatter();
31 //BinaryFormatter formatter = new BinaryFormatter();
33 formatter.Serialize(stream, obj);
34 stream.Close();
36 //Empties obj.
37 obj = null;
39 //Opens file "data.xml" and deserializes the object from it.
40 stream = File.Open("data.xml", FileMode.Open);
41 formatter = new BinaryFormatter();
43 //formatter = new BinaryFormatter();
45 obj = (TestSimpleObject)formatter.Deserialize(stream);
46 stream.Close();
48 Console.WriteLine("");
49 Console.WriteLine("After deserialization the object contains: ");
50 obj.Print();
55 // A test object that needs to be serialized.
56 [Serializable()]
57 public class TestSimpleObject {
59 public Tuple <string,int> member6;
61 public TestSimpleObject() {
62 member6 = new Tuple <string, int> ("aa", 22);
66 public void Print() {
67 Console.WriteLine("member6 = '{0}'", member6);