예제 #1
0
        public void WriteNestedObjectTest()
        {
            SampleClass sampleClass = new SampleClass();

            sampleClass.m_int       = 0;
            sampleClass.m_byte      = 1;
            sampleClass.m_longarray = new List <long>()
            {
                1, -2
            };
            sampleClass.m_string = "test";
            sampleClass.m_obj    = null;

            byte[] expected = new byte[] { 0x00, 0x01, 0x02, 0x02, 0x03, 0x04, 0x74, 0x65, 0x73, 0x74, 0x0D };

            System.IO.MemoryStream actual = new System.IO.MemoryStream();

            BinaryWriter writer = new BinaryWriter(actual, BinaryWriterTest.CannedVersion);

            sampleClass.Serialize(writer);

            TestHelper.AssertCollectionEquals <byte>(expected, actual.ToArray());

            sampleClass.m_obj = new InnerClass()
            {
                m_bool = true, m_double = 0.1, m_float = 150
            };

            List <byte> lb = new List <byte> {
                0x00, 0x01, 0x02, 0x02, 0x03, 0x04, 0x74, 0x65, 0x73, 0x74, 0x05
            };

            lb.AddRange(BitConverter.GetBytes(sampleClass.m_obj.m_float));
            lb.AddRange(BitConverter.GetBytes(sampleClass.m_obj.m_double));
            lb.Add((byte)0xD);

            actual = new System.IO.MemoryStream();

            writer = new BinaryWriter(actual, BinaryWriterTest.CannedVersion);
            sampleClass.Serialize(writer);

            TestHelper.AssertCollectionEquals <byte>(lb.ToArray(), actual.ToArray());
        }
예제 #2
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            SampleClass b = obj as SampleClass;

            if ((System.Object)b == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((this.m_int == b.m_int) && (this.m_byte == b.m_byte) && (this.m_string == b.m_string) &&
                   Enumerable.SequenceEqual <long>(this.m_longarray, b.m_longarray) && (this.m_obj == b.m_obj));
        }