Support for serializing generic object property
Created by: micdenny
be able to serialize property that are generic object (aka boxed), like in this unit test:
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Syroot.BinaryData.Extensions;
namespace Syroot.BinaryData.UnitTest
{
[TestClass]
public class WriteObjectTests
{
[BinaryObject(Explicit = true)]
public class TestObject
{
[BinaryMember(Order = 1)]
public byte GenericPropSize { get; set; }
[BinaryMember(Order = 2)]
public object GenericProp { get; set; }
}
[TestMethod]
public void TestWriteObject()
{
var value = new TestObject
{
GenericPropSize = 2,
GenericProp = (ushort)123
};
byte[] bytes;
using (var stream = new MemoryStream())
{
stream.WriteObject(value, ByteConverter.BigEndian);
bytes = stream.ToArray();
}
Assert.AreEqual(3, bytes.Length);
Assert.AreEqual(2, bytes[0]);
Assert.AreEqual(0, bytes[1]);
Assert.AreEqual(123, bytes[2]);
}
}
}
(ushort)123
could also be (int)123
, etc...
sometimes is useful when you have in the protocol vbinary that actually are one value, but that could be different type so different dimension.
this to avoid having a generic byte[]
but be more typed.....
ok this last sentence it made me think that it's easy when WriteObject, but of course not when you ReadObject, because you don't really know which type is we can understand from a dimension set before, but it's hard to know the real type.
my bad, I think we can throw away this issue, sorry.