コード例 #1
0
        public void SerializeAndDeserialize_MultidimensionalArray()
        {
            var src = new ClassWithMultidimensionalArray
            {
                MultidimensionalArrayInt32 = new[, ]
                {
                    { 1, 2 },
                    { 3, 4 }
                }
            };

            var parameters = new JsonSerializationParameters
            {
                UserDefinedAdapters = new List <IJsonAdapter>
                {
                    new Array2Adapter <int>()
                }
            };

            var json = JsonSerialization.ToJson(src, parameters);

            Assert.That(UnFormat(json), Is.EqualTo("{\"MultidimensionalArrayInt32\":[[1,2],[3,4]]}"));

            var dst = default(ClassWithMultidimensionalArray);

            JsonSerialization.FromJsonOverride(json, ref dst, parameters);
            Assert.That(dst.MultidimensionalArrayInt32, Is.EqualTo(new [, ]
            {
                { 1, 2 },
                { 3, 4 }
            }));
        }
        public void CreatePropertyBag_ClassWithMultidimensionalArray_GeneratesPropertyBag()
        {
            var propertyBag = new ReflectedPropertyBagProvider().CreatePropertyBag <ClassWithMultidimensionalArray>();
            var container   = new ClassWithMultidimensionalArray();

            Assert.That(propertyBag.GetProperties(ref container).Count(), Is.EqualTo(1));
        }
コード例 #3
0
        public void PropertyVisitor_ClassWithMultidimensionalArray_WhenArrayIsNull()
        {
            var container = new ClassWithMultidimensionalArray();

            PropertyContainer.Accept(new EmptyVisitor(), container);
            PropertyContainer.Accept(new EmptyLowLevelVisitor(), container);
        }
        public unsafe void SerializeAndDeserialize_MultidimensionalArray()
        {
            var src = new ClassWithMultidimensionalArray
            {
                MultidimensionalArrayInt32 = new[, ]
                {
                    { 1, 2 },
                    { 3, 4 }
                }
            };

            var parameters = new BinarySerializationParameters
            {
                UserDefinedAdapters = new List <IBinaryAdapter>
                {
                    new Array2Adapter <int>()
                }
            };

            using (var stream = new UnsafeAppendBuffer(16, 4, Allocator.Temp))
            {
                BinarySerialization.ToBinary(&stream, src, parameters);
                var reader = stream.AsReader();
                var dst    = BinarySerialization.FromBinary <ClassWithMultidimensionalArray>(&reader, parameters);

                Assert.That(dst.MultidimensionalArrayInt32, Is.EqualTo(new[, ]
                {
                    { 1, 2 },
                    { 3, 4 }
                }));
            }
        }
コード例 #5
0
        public void PropertyVisitor_ClassWithMultidimensionalArray_WhenArrayIsNotNull()
        {
            var container = new ClassWithMultidimensionalArray
            {
                Int32MultidimensionalArray = new [, ]
                {
                    { 1, 2 },
                    { 3, 4 }
                }
            };

            PropertyContainer.Accept(new EmptyVisitor(), container);
            PropertyContainer.Accept(new EmptyLowLevelVisitor(), container);
        }