コード例 #1
0
        public void TestSerialization()
        {
            StringBuilder builder = new StringBuilder();

            Util.TestSerializer(builder, new ClassWithPrimitiveTypes());
            Util.TestSerializer(builder, new ClassWithArrays());
            Util.TestSerializer(builder, new SuperClassWithPrimitivesAndArrays());
            Util.TestSerializer(builder, new StructWithPrimitiveTypes());
            Util.TestSerializer(builder, new ClassWithWeirdTypes());

            ClassWithPrimitiveTypes c = new ClassWithPrimitiveTypes();

            c.myObject  = new Object();
            c.dayOfWeek = DayOfWeek.Friday;
            c.myString  = "hello[]{}\"\"  \\";

            Util.TestSerializer(builder, c);

            ClassWithArrays ca = new ClassWithArrays();

            ca.ushortArray = new UInt16[] { 0, 99, ushort.MinValue, 7483, ushort.MaxValue, 7575 };
            ca.shortArray  = new Int16[] { short.MinValue, short.MaxValue, 4848 };
            ca.uintArray   = new UInt32[] { uint.MinValue, uint.MaxValue, 9493, 382983, 444, 3443, 14427 };
            ca.intArray    = new Int32[] { int.MinValue, int.MaxValue, -9494593, 384562983, 4244, 344523, 144227 };
            ca.ulongArray  = new UInt64[] { ulong.MinValue, ulong.MaxValue };
            ca.longArray   = new Int64[] { long.MinValue, long.MaxValue };
            ca.enumArray   = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Saturday, DayOfWeek.Wednesday, DayOfWeek.Friday };
            ca.objectArray = new Object[] { new Object(), null, new Object() };
            ca.stringArray = new String[] { null, String.Empty, "hello", "[]", "{,,,}" };

            Console.WriteLine(ca.SerializeObject());
            Util.TestSerializer(builder, ca);

            SuperClassWithPrimitivesAndArrays sca = new SuperClassWithPrimitivesAndArrays();

            sca.c  = c;
            sca.ca = ca;

            SuperClassWithPrimitivesAndArrays scaMess1 = new SuperClassWithPrimitivesAndArrays();
            SuperClassWithPrimitivesAndArrays scaMess2 = new SuperClassWithPrimitivesAndArrays();

            scaMess1.c  = c;
            scaMess2.c  = c;
            scaMess1.ca = ca;
            scaMess2.ca = ca;
            sca.mess    = new SuperClassWithPrimitivesAndArrays[] { scaMess1, scaMess2 };


            Util.TestSerializer(builder, sca);
        }
コード例 #2
0
ファイル: Libraries.cs プロジェクト: RichardBradley/MMEd
        public void TestXmlArraySerialisation()
        {
            ClassWithArrays o = new ClassWithArrays();

            o.twoDeeCStyle = new int[2][];
            for (int i = 0; i < o.twoDeeCStyle.Length; i++)
            {
                o.twoDeeCStyle[i] = new int[2];
            }
            //o.twoDeeVBStyle = new int[2,2];
            StringWriter  sw = new StringWriter();
            XmlSerializer xs = new XmlSerializer(typeof(ClassWithArrays));

            xs.Serialize(sw, o);
            Console.Out.WriteLine(sw.ToString());
        }
コード例 #3
0
		public void SaveAndLoadClassWithArrays()
		{
			var instance = new ClassWithArrays();
			var data = BinaryDataExtensions.SaveDataIntoMemoryStream(instance);
			var retrieved =
				BinaryDataExtensions.LoadDataWithKnownTypeFromMemoryStream<ClassWithArrays>(data);
			Assert.IsTrue(retrieved.byteData.Compare(new byte[] { 1, 2, 3, 4, 5 }),
				retrieved.byteData.ToText());
			Assert.IsTrue(retrieved.charData.Compare(new[] { 'a', 'b', 'c' }),
				retrieved.charData.ToText());
			Assert.IsTrue(retrieved.intData.Compare(new[] { 10, 20, 30 }), retrieved.intData.ToText());
			Assert.IsTrue(retrieved.stringData.Compare(new[] { "Hi", "there" }),
				retrieved.stringData.ToText());
			Assert.IsTrue(retrieved.enumData.Compare(new[] { DayOfWeek.Monday, DayOfWeek.Sunday }),
				retrieved.enumData.ToText());
			Assert.IsTrue(retrieved.byteEnumData.Compare(new[] { ByteEnum.Normal, ByteEnum.High }),
				retrieved.byteEnumData.ToText());
		}
コード例 #4
0
        public void SaveAndLoadClassWithArrays()
        {
            var instance  = new ClassWithArrays();
            var data      = BinaryDataExtensions.SaveDataIntoMemoryStream(instance);
            var retrieved =
                BinaryDataExtensions.LoadDataWithKnownTypeFromMemoryStream <ClassWithArrays>(data);

            Assert.IsTrue(retrieved.byteData.Compare(new byte[] { 1, 2, 3, 4, 5 }),
                          retrieved.byteData.ToText());
            Assert.IsTrue(retrieved.charData.Compare(new[] { 'a', 'b', 'c' }),
                          retrieved.charData.ToText());
            Assert.IsTrue(retrieved.intData.Compare(new[] { 10, 20, 30 }), retrieved.intData.ToText());
            Assert.IsTrue(retrieved.stringData.Compare(new[] { "Hi", "there" }),
                          retrieved.stringData.ToText());
            Assert.IsTrue(retrieved.enumData.Compare(new[] { DayOfWeek.Monday, DayOfWeek.Sunday }),
                          retrieved.enumData.ToText());
            Assert.IsTrue(retrieved.byteEnumData.Compare(new[] { ByteEnum.Normal, ByteEnum.High }),
                          retrieved.byteEnumData.ToText());
        }
コード例 #5
0
ファイル: Libraries.cs プロジェクト: RichardBradley/MMEd
 public void TestXmlArraySerialisation()
 {
     ClassWithArrays o = new ClassWithArrays();
       o.twoDeeCStyle = new int[2][];
       for (int i = 0; i < o.twoDeeCStyle.Length; i++)
       {
     o.twoDeeCStyle[i] = new int[2];
       }
       //o.twoDeeVBStyle = new int[2,2];
       StringWriter sw = new StringWriter();
       XmlSerializer xs = new XmlSerializer(typeof(ClassWithArrays));
       xs.Serialize(sw, o);
       Console.Out.WriteLine(sw.ToString());
 }