private TLSerializationMode?GetVectorItemsSerializationModeOverride(ITLVectorSerializer vectorSerializer, PropertyInfo propertyInfo,
                                                                            TLSerializationContext context)
        {
            Type propType = propertyInfo.PropertyType;

            if (vectorSerializer.SupportedType != propType)
            {
                throw new NotSupportedException(string.Format("Current vector serializer doesn't support type: {0}. It supports: {1}", propType,
                                                              vectorSerializer.SupportedType));
            }

            TLSerializationMode?itemsSerializationModeOverride = TLSerializationMode.Bare;

            // Check for items serializer.
            // If items have multiple constructors or have a TLTypeAttribute (in other words it is TL type),
            // then items must be serialized as boxed.
            Type          itemsType            = vectorSerializer.ItemsType;
            ITLSerializer vectorItemSerializer = context.Rig.GetSerializerByObjectType(itemsType);

            if (vectorItemSerializer is ITLMultiConstructorSerializer || itemsType.GetTypeInfo().GetCustomAttribute <TLTypeAttribute>() != null)
            {
                itemsSerializationModeOverride = TLSerializationMode.Boxed;
            }
            else
            {
                // Check for TLVector attribute with items serialization mode override.
                var tlVectorAttribute = propertyInfo.GetCustomAttribute <TLVectorAttribute>();
                if (tlVectorAttribute != null)
                {
                    itemsSerializationModeOverride = tlVectorAttribute.ItemsModeOverride;
                }
            }
            return(itemsSerializationModeOverride);
        }
 public TLVectorPropertySerializationAgent(TLPropertyInfo tlPropertyInfo, ITLVectorSerializer serializer, TLSerializationMode? itemsSerializationModeOverride)
     : base(tlPropertyInfo)
 {
     _serializer = serializer;
     _itemsSerializationModeOverride = itemsSerializationModeOverride;
 }
        private static TLSerializationMode? GetVectorItemsSerializationModeOverride(
            ITLVectorSerializer vectorSerializer,
            PropertyInfo propertyInfo,
            TLSerializersBucket serializersBucket)
        {
            Type propType = propertyInfo.PropertyType;

            if (vectorSerializer.SupportedType != propType)
            {
                throw new NotSupportedException(
                    string.Format("Current vector serializer doesn't support type: {0}. It supports: {1}", propType, vectorSerializer.SupportedType));
            }

            TLSerializationMode? itemsSerializationModeOverride = TLSerializationMode.Bare;

            // Check for items serializer.
            // If items have multiple constructors or have a TLTypeAttribute (in other words it is TL type),
            // then items must be serialized as boxed.
            Type itemsType = vectorSerializer.ItemsType;
            ITLSerializer vectorItemSerializer = serializersBucket[itemsType];
            if (vectorItemSerializer is ITLMultiConstructorSerializer || itemsType.GetTypeInfo().GetCustomAttribute<TLTypeAttribute>() != null)
            {
                itemsSerializationModeOverride = TLSerializationMode.Boxed;
            }
            else
            {
                // Check for TLVector attribute with items serialization mode override.
                var tlVectorAttribute = propertyInfo.GetCustomAttribute<TLVectorAttribute>();
                if (tlVectorAttribute != null)
                {
                    itemsSerializationModeOverride = tlVectorAttribute.ItemsModeOverride;
                }
            }
            return itemsSerializationModeOverride;
        }
Example #4
0
 public TLVectorPropertySerializationAgent(TLPropertyInfo tlPropertyInfo, ITLVectorSerializer serializer, TLSerializationMode?itemsSerializationModeOverride)
     : base(tlPropertyInfo)
 {
     _serializer = serializer;
     _itemsSerializationModeOverride = itemsSerializationModeOverride;
 }