Beispiel #1
0
        public void CombineTest()
        {
            //Define our people
            Variant people = JSON.Load("[{\"@index\":0,\"name\":\"Jenny\",\"age\":12},{\"@index\":1,\"name\":\"Frank\",\"age\":32}]");

            //Redefine person[1] name to Mike from Frank
            Variant nameOverride = JSON.Load("[{\"@index\":1,\"name\":\"Mike\"}]");

            //Redefine person[1] age to 100 from 32
            Variant ageOverride = JSON.Load("[{\"@index\":1,\"age\":100}]");

            //Merge three variants into one ProxyArray
            ProxyArray peopleArray = Variant.CombineInto <ProxyArray>(people, nameOverride, ageOverride);


            Person[] persons = peopleArray.Make <Person[]>();

            Assert.AreEqual(2, persons.Length);
            Assert.AreEqual("Jenny", persons[0].name);
            Assert.AreEqual(12, persons[0].age);
            Assert.AreEqual("Mike", persons[1].name);
            Assert.AreEqual(100, persons[1].age);

            for (int i = 0; i < persons.Length; i++)
            {
                Console.WriteLine(persons[i].name + " is " + persons[i].age + " years old");
            }
        }