/// <summary>
        /// Sets the <see cref="TypeSerializer{T}"/> instance to use overriding the default ones.
        /// </summary>
        private void SetSpecificSerializers(IEnumerable <ITypeSerializer> typeSerializers)
        {
            if (typeSerializers == null)
            {
                return;
            }
            var defined = new HashSet <ColumnTypeCode>();

            foreach (var ts in typeSerializers)
            {
                if (defined.Contains(ts.CqlType))
                {
                    //a serializer for a type that was already defined
                    //log a warning and ignore it.
                    Logger.Warning("A TypeSerializer for {0} has already been defined, ignoring {1}", ts.CqlType, ts.GetType().Name);
                    continue;
                }
                if (ts.CqlType == ColumnTypeCode.Custom)
                {
                    _customDeserializers[ts.TypeInfo] = ts;
                    _customSerializers[ts.Type]       = ts;
                    Logger.Info("Using {0} serializer for custom type '{1}'", ts.GetType().Name, ((CustomColumnInfo)ts.TypeInfo).CustomTypeName);
                    continue;
                }
                //Only one per CQL type, except for Custom.
                defined.Add(ts.CqlType);
                if (ts.CqlType == ColumnTypeCode.Udt)
                {
                    _udtSerializer = (UdtSerializer)ts;
                    Logger.Info("Using {0} serializer for UDT types", ts.GetType().Name);
                    continue;
                }
                if (_primitiveDeserializers.ContainsKey(ts.CqlType))
                {
                    Logger.Info("Using {0} serializer for primitive type {1}", ts.GetType().Name, ts.CqlType);
                    _primitiveDeserializers[ts.CqlType] = ts;
                    _primitiveSerializers[ts.Type]      = ts;
                    continue;
                }
                throw new DriverInternalError("TypeSerializer defined for unsupported CQL type " + ts.CqlType);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets the <see cref="TypeSerializer{T}"/> instance to use overriding the default ones.
        /// </summary>
        public void SetSpecificSerializers(IEnumerable <ITypeSerializer> typeSerializers)
        {
            if (typeSerializers == null)
            {
                typeSerializers = new List <ITypeSerializer>(0);
            }

            var defined = new HashSet <ColumnTypeCode>();

            foreach (var ts in typeSerializers)
            {
                if (defined.Contains(ts.CqlType))
                {
                    //a serializer for a type that was already defined
                    //log a warning and ignore it.
                    Logger.Warning($"A TypeSerializer for {ts.CqlType} has already been defined, ignoring {ts.GetType().Name}");
                    continue;
                }
                if (ts.CqlType == ColumnTypeCode.Custom)
                {
                    _customDeserializers[ts.TypeInfo] = ts;
                    _customSerializers[ts.Type]       = ts;
                    Logger.Info($"Using {ts.GetType().Name} serializer for custom type '{((CustomColumnInfo)ts.TypeInfo).CustomTypeName}'");
                    continue;
                }
                //Only one per CQL type, except for Custom.
                defined.Add(ts.CqlType);
                if (ts.CqlType == ColumnTypeCode.Udt)
                {
                    _udtSerializer = (UdtSerializer)ts;
                    Logger.Info($"Using {ts.GetType().Name} serializer for UDT types");
                    continue;
                }
                if (_primitiveDeserializers.ContainsKey(ts.CqlType))
                {
                    Logger.Info($"Using {ts.GetType().Name} serializer for primitive type {ts.CqlType}");
                    _primitiveDeserializers[ts.CqlType] = ts;
                    _primitiveSerializers[ts.Type]      = ts;
                    continue;
                }
                throw new DriverInternalError($"TypeSerializer defined for unsupported CQL type {ts.CqlType}");
            }

            // add default custom serializers
            foreach (var defaultCustomSerializer in _defaultCustomTypeSerializers)
            {
                if (defaultCustomSerializer.CqlType != ColumnTypeCode.Custom)
                {
                    throw new DriverInternalError("Expected custom type serializers only.");
                }

                if (_customDeserializers.ContainsKey(defaultCustomSerializer.TypeInfo) ||
                    _customSerializers.ContainsKey(defaultCustomSerializer.Type))
                {
                    // user overrode default serializer, not logging anything because
                    // it would be logged twice due to SerializerManager.Default and we also
                    // don't log anything for the other default serializers
                    continue;
                }

                _customDeserializers[defaultCustomSerializer.TypeInfo] = defaultCustomSerializer;
                _customSerializers[defaultCustomSerializer.Type]       = defaultCustomSerializer;
            }
        }