Example #1
0
        public static string ToJson <T>(List <T> list, bool prettyPrint)
        {
            WrapperList <T> wrapper = new WrapperList <T>();

            wrapper.Items = list;
            return(JsonUtility.ToJson(wrapper, prettyPrint));
        }
Example #2
0
    public static string ToJsonList <T>(List <T> list)
    {
        WrapperList <T> wrapperList = new WrapperList <T>();

        wrapperList.Items = list;
        return(JsonUtility.ToJson(wrapperList, true));
    }
        public void ListToOtherElementConcurrentStack()
        {
            var converter   = new TestObjectConverter();
            var source      = new WrapperList <int>(new[] { 0, 1 });
            var destination = (ConcurrentStack <string>)converter.Convert(source, typeof(ConcurrentStack <string>));

            Assert.Equal(2, destination.Count);
            Assert.Contains("0", destination);
            Assert.Contains("1", destination);
            Assert.True(converter.UsedIn(typeof(EnumerableConverterFactory), typeof(ToStringConverterFactory)));
        }
        public void ListToSameElementConcurrentStack()
        {
            var converter   = new TestObjectConverter();
            var source      = new WrapperList <int>(new[] { 0, 1 });
            var destination = (ConcurrentStack <int>)converter.Convert(source, typeof(ConcurrentStack <int>));

            Assert.Equal(2, destination.Count);
            Assert.Contains(0, destination);
            Assert.Contains(1, destination);
            Assert.True(converter.UsedOnly <EnumerableConverterFactory>());
        }
Example #5
0
        public void ListToOtherElementReadOnlyCollection()
        {
            var converter   = new TestObjectConverter();
            var source      = new WrapperList <int>(new[] { 0, 1 });
            var destination = (ReadOnlyCollection <string>)converter.Convert(source, typeof(ReadOnlyCollection <string>));

            Assert.Equal(2, destination.Count);
            Assert.Equal("0", destination[0]);
            Assert.Equal("1", destination[1]);
            Assert.True(converter.UsedIn(typeof(EnumerableConverterFactory), typeof(ToStringConverterFactory)));
        }
Example #6
0
        public void ListToSameElementReadOnlyCollection()
        {
            var converter   = new TestObjectConverter();
            var source      = new WrapperList <int>(new[] { 0, 1 });
            var destination = (ReadOnlyCollection <int>)converter.Convert(source, typeof(ReadOnlyCollection <int>));

            Assert.Equal(2, destination.Count);
            Assert.Equal(0, destination[0]);
            Assert.Equal(1, destination[1]);
            Assert.True(converter.UsedOnly <EnumerableConverterFactory>());
        }
        public static List <T> DeSerialize <T>(string json)
        {
            if (!json.StartsWith("{", System.StringComparison.Ordinal))
            {
                json = "{\"v\":" + json + "}";
            }

            WrapperList <T> list = JsonUtility.FromJson <WrapperList <T> >(json);

            return(list.v);
        }
Example #8
0
        public static List <T> FromJson <T>(string json)
        {
            WrapperList <T> wrapper = JsonUtility.FromJson <WrapperList <T> >(json);

            return(wrapper.Items);
        }