Exemplo n.º 1
0
    unsafe public void ReadWriteBoxedWithStringArrayWithOneElement()
    {
        var srcData = new ComponentWithStringArray()
        {
            StringArray = new string[] { "One" }
        };

        // Write to stream
        var buffer = new UnsafeAppendBuffer(0, 16, Allocator.Persistent);
        var writer = new ManagedObjectBinaryWriter(&buffer);

        var boxedSrcData = (object)srcData;

        writer.WriteObject(boxedSrcData);

        var objectTable = writer.GetUnityObjects();

        // Read from stream
        var readStream = buffer.AsReader();
        var reader     = new ManagedObjectBinaryReader(&readStream, objectTable);

        var boxedRead = reader.ReadObject(typeof(ComponentWithStringArray));

        // Check same
        ComponentWithStringArray.AreEqual(srcData, (ComponentWithStringArray)boxedRead);

        buffer.Dispose();
    }
Exemplo n.º 2
0
    unsafe public void ReadWriteBoxedWithStringArrayWithOneElement()
    {
        var srcData = new ComponentWithStringArray()
        {
            StringArray = new string[] { "One" }
        };

        // Write to stream
        var buffer = new UnsafeAppendBuffer(0, 16, Allocator.Persistent);
        var writer = new PropertiesBinaryWriter(&buffer);

        var boxedSrcData = (object)srcData;

        BoxedProperties.WriteBoxedType(boxedSrcData, writer);

        var objectTable = writer.GetObjectTable();

        // Read from stream
        var readStream = writer.Buffer.AsReader();
        var reader     = new PropertiesBinaryReader(&readStream, objectTable);

        var boxedRead = BoxedProperties.ReadBoxedClass(typeof(ComponentWithStringArray), reader);

        // Check same
        ComponentWithStringArray.AreEqual(srcData, (ComponentWithStringArray)boxedRead);

        buffer.Dispose();
    }