Пример #1
0
        public static void ReadArrayListOfArray()
        {
            ArrayList result   = JsonSerializer.Deserialize <ArrayList>(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]"));
            int       expected = 1;

            foreach (JsonElement arr in result)
            {
                foreach (JsonElement i in arr.EnumerateArray())
                {
                    Assert.Equal(expected++, i.GetInt32());
                }
            }

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

            expected = 1;

            foreach (JsonElement arr in result2)
            {
                foreach (JsonElement i in arr.EnumerateArray())
                {
                    Assert.Equal(expected++, i.GetInt32());
                }
            }
        }
        public void Initialize()
        {
            MyIListWrapper = new WrapperForIList()
            {
                "Hello"
            };
            MyIDictionaryWrapper = new WrapperForIDictionary()
            {
                { "key", "value" }
            };
            MyHashtableWrapper = new HashtableWrapper(new List <KeyValuePair <string, object> > {
                new KeyValuePair <string, object>("key", "value")
            });
            MyArrayListWrapper = new ArrayListWrapper()
            {
                "Hello"
            };
            MySortedListWrapper = new SortedListWrapper()
            {
                { "key", "value" }
            };
            MyStackWrapper = new StackWrapper();
            MyQueueWrapper = new QueueWrapper();

            MyStackWrapper.Push("Hello");
            MyQueueWrapper.Enqueue("Hello");
        }
        public async Task WriteArrayListOfArrayList()
        {
            ArrayList input = new ArrayList
            {
                new ArrayList(new List <int>()
                {
                    1, 2
                }),
                new ArrayList(new List <int>()
                {
                    3, 4
                })
            };

            string json = await Serializer.SerializeWrapper(input);

            Assert.Equal("[[1,2],[3,4]]", json);

            ArrayListWrapper input2 = new ArrayListWrapper(new List <object>
            {
                new ArrayListWrapper(new List <object>()
                {
                    1, 2
                }),
                new ArrayListWrapper(new List <object>()
                {
                    3, 4
                })
            });

            json = await Serializer.SerializeWrapper(input2);

            Assert.Equal("[[1,2],[3,4]]", json);
        }
        public async Task ReadArrayListOfArray()
        {
            ArrayList result = await Serializer.DeserializeWrapper <ArrayList>(@"[[1,2],[3,4]]");

            int expected = 1;

            foreach (JsonElement arr in result)
            {
                foreach (JsonElement i in arr.EnumerateArray())
                {
                    Assert.Equal(expected++, i.GetInt32());
                }
            }

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

            expected = 1;

            foreach (JsonElement arr in result2)
            {
                foreach (JsonElement i in arr.EnumerateArray())
                {
                    Assert.Equal(expected++, i.GetInt32());
                }
            }
        }
Пример #5
0
        public static void WriteArrayListOfArrayList()
        {
            ArrayList input = new ArrayList
            {
                new ArrayList(new List <int>()
                {
                    1, 2
                }),
                new ArrayList(new List <int>()
                {
                    3, 4
                })
            };

            string json = JsonSerializer.Serialize(input);

            Assert.Equal("[[1,2],[3,4]]", json);

            ArrayListWrapper input2 = new ArrayListWrapper(new List <object>
            {
                new ArrayListWrapper(new List <object>()
                {
                    1, 2
                }),
                new ArrayListWrapper(new List <object>()
                {
                    3, 4
                })
            });

            json = JsonSerializer.Serialize(input2);
            Assert.Equal("[[1,2],[3,4]]", json);
        }
Пример #6
0
            /// <seealso cref="VelMethod.invoke(java.lang.Object, java.lang.Object[])">
            /// </seealso>
            public virtual object Invoke(object instance, object[] parameters)
            {
                // if we're pretending an array is a list...
                if (wrapArray)
                {
                    instance = new ArrayListWrapper(instance);
                }

                if (VarArg)
                {
                    ParameterInfo[] formal = method.GetParameters();
                    int             index  = formal.Length - 1;
                    if (parameters.Length >= index)
                    {
                        System.Type type = formal[index].GetType().GetElementType();
                        parameters = handleVarArg(type, index, parameters);
                    }
                }

                // call extension point invocation
                return(DoInvoke(instance, parameters));
            }