Exemplo n.º 1
0
        /// <exception cref="java.lang.InstantiationException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private IEnumerable DeserializeCollection(VPackSlice parent, VPackSlice vpack, Type type, Type contentType)
        {
            var   info   = type.GetTypeInfo();
            long  length = vpack.GetLength();
            IList value;

            if (typeof(IList).GetTypeInfo().IsAssignableFrom(info) && info.IsClass)
            {
                value = (IList)CreateInstance(type);
            }
            else
            {
                value = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(contentType), (int)length);
            }

            if (length > 0)
            {
                for (int i = 0; i < length; i++)
                {
                    value.Add(GetValue(parent, vpack.Get(i), contentType, null));
                }
            }

            return(value);
        }
Exemplo n.º 2
0
        /// <exception cref="java.lang.InstantiationException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private IDictionary DeserializeMap(VPackSlice parent, VPackSlice vpack, Type type, Type keyType, Type valueType)
        {
            var         info   = type.GetTypeInfo();
            int         length = vpack.GetLength();
            IDictionary value;

            if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(info) && info.IsClass)
            {
                value = (IDictionary)CreateInstance(type);
            }
            else
            {
                value = new Dictionary <object, object>(length);
            }
            if (length > 0)
            {
                IVPackKeyMapAdapter keyMapAdapter = this.GetKeyMapAdapter(keyType);
                if (keyMapAdapter != null)
                {
                    for (IEnumerator <IEntry <string, VPackSlice> > iterator = vpack.ObjectIterator();
                         iterator.MoveNext();)
                    {
                        IEntry <string, VPackSlice> next = iterator.Current;
                        object name = keyMapAdapter.Deserialize(next.Key);
                        value[name] = GetValue(vpack, next.Value, valueType, name.ToString());
                    }
                }
                else
                {
                    for (int i = 0; i < vpack.GetLength(); i++)
                    {
                        VPackSlice entry    = vpack.Get(i);
                        object     mapKey   = GetValue(parent, entry.Get(ATTR_KEY), keyType, null);
                        object     mapValue = GetValue(parent, entry.Get(ATTR_VALUE), valueType, null);
                        value[mapKey] = mapValue;
                    }
                }
            }

            return(value);
        }
Exemplo n.º 3
0
        /// <exception cref="java.lang.InstantiationException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private Array DeserializeArray(VPackSlice parent, VPackSlice vpack, Type type)
        {
            int length = vpack.GetLength();

            Type  subType = type.GetElementType();
            Array value   = Array.CreateInstance(subType, length);

            for (int i = 0; i < length; i++)
            {
                value.SetValue(GetValue(parent, vpack.Get(i), subType, null), i);
            }

            return(value);
        }
Exemplo n.º 4
0
        /// <exception cref="VPackException"/>
        private void ParseArray(VPackSlice value, StringBuilder json, bool includeNullValues)
        {
            json.Append(ARRAY_OPEN);
            int added = 0;

            for (int i = 0; i < value.GetLength(); i++)
            {
                VPackSlice valueAt = value.Get(i);
                if (!valueAt.IsNull || includeNullValues)
                {
                    if (added++ > 0)
                    {
                        json.Append(SEPARATOR);
                    }

                    this.Parse(value, null, valueAt, json, includeNullValues);
                }
            }

            json.Append(ARRAY_CLOSE);
        }