Exemple #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 object DeserializeObject(VPackSlice parent, VPackSlice vpack, Type type, string fieldName)
        {
            object             entity;
            IVPackDeserializer deserializer = this.GetDeserializer(fieldName, type);

            if (deserializer != null)
            {
                entity = deserializer.Deserialize(parent, vpack, this.deserializationContext);
            }
            else
            {
                if (type == typeof(object))
                {
                    entity = GetValue(parent, vpack, this.getType(vpack), fieldName);
                }
                else
                {
                    entity = CreateInstance(type);
                    this.DeserializeFields(entity, vpack);
                }
            }

            return(entity);
        }
Exemple #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 object GetValue(VPackSlice parent, VPackSlice vpack, Type type, string fieldName)
        {
            object value;
            Type   tmpType;

            if (vpack.IsNull)
            {
                value = null;
            }
            else
            {
                IVPackDeserializer deserializer = this.GetDeserializer(fieldName, type);
                if (deserializer != null)
                {
                    value = deserializer.Deserialize(parent, vpack, this.deserializationContext);
                }
                else
                {
                    var info = type.GetTypeInfo();
                    if (type.IsGenericParameter)
                    {
                        if (!type.IsConstructedGenericType)
                        {
                            throw new TypeLoadException(string.Format("Creating open generic types are not supported. ({0})", type));
                        }

                        Type[] gens;

                        if (typeof(IDictionary <,>).GetTypeInfo().IsAssignableFrom(info))
                        {
                            gens  = type.GetTargetType(typeof(IDictionary <,>)).GenericTypeArguments;
                            value = DeserializeMap(parent, vpack, type, gens[0], gens[1]);
                        }
                        else if (typeof(IEnumerable <>).GetTypeInfo().IsAssignableFrom(info))
                        {
                            gens  = type.GetTargetType(typeof(IEnumerable <>)).GenericTypeArguments;
                            value = DeserializeCollection(parent, vpack, type, gens[0]);
                        }
                        else
                        {
                            value = DeserializeObject(parent, vpack, type, fieldName);
                        }
                    }
                    else
                    {
                        Type rawType = typeof(object);
                        if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(info))
                        {
                            value = DeserializeMap(parent, vpack, type, rawType, rawType);
                        }
                        else if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(info))
                        {
                            value = DeserializeCollection(parent, vpack, type, rawType);
                        }
                        else if (info.IsArray)
                        {
                            value = DeserializeArray(parent, vpack, type);
                        }
                        else if (info.IsEnum)
                        {
                            value = Enum.Parse(type, vpack.AsString);
                        }
                        else
                        {
                            value = DeserializeObject(parent, vpack, type, fieldName);
                        }
                    }
                }
            }

            return(value);
        }