コード例 #1
0
        public static void ReadSimpleGenericIList()
        {
            IList <int> result   = JsonSerializer.Deserialize <IList <int> >(Encoding.UTF8.GetBytes(@"[1,2]"));
            int         expected = 1;

            foreach (int i in result)
            {
                Assert.Equal(expected++, i);
            }

            result = JsonSerializer.Deserialize <IList <int> >(Encoding.UTF8.GetBytes(@"[]"));
            Assert.Equal(0, result.Count());

            StringIListWrapper result2 = JsonSerializer.Deserialize <StringIListWrapper>(@"[""1"",""2""]");

            expected = 1;

            foreach (string str in result2)
            {
                Assert.Equal($"{expected++}", str);
            }

            result2 = JsonSerializer.Deserialize <StringIListWrapper>(@"[]");
            Assert.Equal(0, result2.Count());
        }
コード例 #2
0
        public async Task ReadSimpleGenericIList()
        {
            IList <int> result = await Serializer.DeserializeWrapper <IList <int> >(@"[1,2]");

            int expected = 1;

            foreach (int i in result)
            {
                Assert.Equal(expected++, i);
            }

            result = await Serializer.DeserializeWrapper <IList <int> >(@"[]");

            Assert.Equal(0, result.Count());

            StringIListWrapper result2 = await Serializer.DeserializeWrapper <StringIListWrapper>(@"[""1"",""2""]");

            expected = 1;

            foreach (string str in result2)
            {
                Assert.Equal($"{expected++}", str);
            }

            result2 = await Serializer.DeserializeWrapper <StringIListWrapper>(@"[]");

            Assert.Equal(0, result2.Count());
        }