예제 #1
0
        /// <inheritdoc />
        public bool TryDictify(
            dynamic objectData,
            IGraphSONWriter serializer,
            IGenericSerializer genericSerializer,
            out dynamic result)
        {
            if (objectData == null)
            {
                result = null;
                return(false);
            }

            var type = (Type)objectData.GetType();
            var map  = genericSerializer.GetUdtMapByType(type);

            if (map == null)
            {
                result = null;
                return(false);
            }

            var dict = GetUdtTypeDefinition(map, genericSerializer);

            var value  = (object)objectData;
            var values = new List <object>();

            foreach (var field in map.Definition.Fields)
            {
                object fieldValue      = null;
                var    prop            = map.GetPropertyForUdtField(field.Name);
                var    fieldTargetType = genericSerializer.GetClrTypeForGraph(field.TypeCode, field.TypeInfo);
                if (prop != null)
                {
                    fieldValue = prop.GetValue(value, null);
                    if (!fieldTargetType.GetTypeInfo().IsAssignableFrom(prop.PropertyType.GetTypeInfo()))
                    {
                        fieldValue = UdtMap.TypeConverter.ConvertToDbFromUdtFieldValue(prop.PropertyType,
                                                                                       fieldTargetType,
                                                                                       fieldValue);
                    }
                }

                values.Add(fieldValue);
            }

            dict.Add("value", values.Select(serializer.ToDict));
            result = GraphSONUtil.ToTypedValue("UDT", dict, "dse");
            return(true);
        }
예제 #2
0
 public Type GetClrTypeForGraph(ColumnTypeCode typeCode, IColumnInfo typeInfo)
 {
     return(_serializer.GetClrTypeForGraph(typeCode, typeInfo));
 }