コード例 #1
0
ファイル: VPack.cs プロジェクト: composite/ArangoDB.Net
 /// <exception cref="System.MissingMethodException"/>
 /// <exception cref="java.lang.IllegalAccessException"/>
 /// <exception cref="java.lang.reflect.InvocationTargetException"/>
 /// <exception cref="java.lang.InstantiationException"/>
 /// <exception cref="VPackException"/>
 private void DeserializeField(
     VPackSlice parent,
     VPackSlice vpack,
     object entity,
     VPackCache.FieldInfo fieldInfo)
 {
     if (!vpack.IsNone)
     {
         object value = GetValue(parent, vpack, fieldInfo.Type, fieldInfo.FieldName);
         fieldInfo.set(entity, value);
     }
 }
コード例 #2
0
ファイル: VPack.cs プロジェクト: composite/ArangoDB.Net
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void SerializeField(
            object entity,
            VPackBuilder builder,
            VPackCache.FieldInfo fieldInfo,
            IDictionary <string, object> additionalFields)
        {
            string fieldName = fieldInfo.FieldName;
            Type   type      = fieldInfo.Type;
            object value     = fieldInfo.get(entity);

            this.AddValue(fieldName, type, value, builder, fieldInfo, additionalFields);
        }
コード例 #3
0
ファイル: VPack.cs プロジェクト: composite/ArangoDB.Net
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="java.lang.InstantiationException"/>
        /// <exception cref="VPackException"/>
        private void DeserializeFields(object entity, VPackSlice vpack)
        {
            IDictionary <string, VPackCache.FieldInfo> fields = this.cache.getFields(entity.GetType());

            for (IEnumerator <IEntry <string, VPackSlice> > iterator = vpack.ObjectIterator(); iterator.MoveNext();)
            {
                IEntry <string, VPackSlice> next      = iterator.Current;
                VPackCache.FieldInfo        fieldInfo = fields[next.Key];
                if (fieldInfo != null && fieldInfo.IsDeserialize)
                {
                    this.DeserializeField(vpack, next.Value, entity, fieldInfo);
                }
            }
        }
コード例 #4
0
ファイル: VPack.cs プロジェクト: composite/ArangoDB.Net
        /// <exception cref="System.MissingMethodException"/>
        /// <exception cref="java.lang.IllegalAccessException"/>
        /// <exception cref="java.lang.reflect.InvocationTargetException"/>
        /// <exception cref="VPackException"/>
        private void AddValue(
            string name,
            Type type,
            object value,
            VPackBuilder builder,
            VPackCache.FieldInfo fieldInfo,
            IDictionary <string, object> additionalFields)
        {
            if (value == null)
            {
                if (this.serializeNullValues)
                {
                    builder.Add(name, ValueType.NULL);
                }
            }
            else
            {
                IVPackSerializer serializer = this.serializers[type];
                if (serializer != null)
                {
                    serializer.Serialize(builder, name, value, this.serializationContext);
                }
                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;
                            this.SerializeMap(name, value, builder, gens[0], additionalFields);
                        }
                        else if (typeof(IEnumerable <>).GetTypeInfo().IsAssignableFrom(info))
                        {
                            this.SerializeIterable(name, value, builder, additionalFields);
                        }
                        else if (type.IsConstructedGenericType)
                        {
                            this.SerializeObject(name, value, builder, additionalFields);
                        }
                    }
                    else
                    {
                        if (typeof(IDictionary).GetTypeInfo().IsAssignableFrom(info))
                        {
                            this.SerializeMap(name, value, builder, typeof(string), additionalFields);
                        }
                        else if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(info))
                        {
                            this.SerializeIterable(name, value, builder, additionalFields);
                        }
                        else if (info.IsArray)
                        {
                            this.SerializeArray(name, (Array)value, builder, additionalFields);
                        }
                        else
                        {
                            this.SerializeObject(name, value, builder, additionalFields);
                        }
                    }
                }
            }
        }