Ejemplo n.º 1
0
        protected void Base_EmptyStructUdpMessageSerialization(ISerializer serializer)
        {
            var myStruct = new MyEmptyStruct();

            UdpMessage message = UdpMessage.Create(myStruct, serializer);

            ReadOnlyMemory <byte> data = serializer.Serialize(message);

            var nongenericMessage = serializer.Deserialize(data, typeof(UdpMessage));
            var genericMessage    = serializer.Deserialize <UdpMessage>(data);

            object nongenericDto = null;

            if (nongenericMessage is UdpMessage ngm)
            {
                nongenericDto = ngm.GetData(typeof(MyEmptyStruct), serializer);
            }
            else
            {
                Assert.True(false, $"{nameof(nongenericMessage)} was not of expected type {nameof(UdpMessage)}.");
            }

            var genericDto = genericMessage.GetData <MyEmptyStruct>(serializer);

            AssertExtensions.AreSame(myStruct, nongenericDto);
            AssertExtensions.AreSame(myStruct, genericDto);
        }