Exemplo n.º 1
0
        TypeHandler RegisterArrayType(uint oid, TypeHandler elementHandler, char textDelimiter)
        {
            ArrayHandler arrayHandler;

            var asBitStringHandler = elementHandler as BitStringHandler;

            if (asBitStringHandler != null)
            {
                // BitString requires a special array handler which returns bool or BitArray
                arrayHandler = new BitStringArrayHandler(asBitStringHandler, textDelimiter);
            }
            else if (elementHandler is ITypeHandlerWithPsv)
            {
                var arrayHandlerType = typeof(ArrayHandlerWithPsv <,>).MakeGenericType(elementHandler.GetFieldType(), elementHandler.GetProviderSpecificFieldType());
                arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler, textDelimiter);
            }
            else
            {
                var arrayHandlerType = typeof(ArrayHandler <>).MakeGenericType(elementHandler.GetFieldType());
                arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler, textDelimiter);
            }

            arrayHandler.PgName = "array";
            arrayHandler.OID    = oid;
            _oidIndex[oid]      = arrayHandler;

            return(arrayHandler);
        }
Exemplo n.º 2
0
        void RegisterArrayType(BackendType backendType)
        {
            Contract.Requires(backendType.Element != null);

            TypeHandler elementHandler;

            if (!_oidIndex.TryGetValue(backendType.Element.OID, out elementHandler))
            {
                // Array type referring to an unhandled element type
                return;
            }

            ArrayHandler arrayHandler;

            var asBitStringHandler = elementHandler as BitStringHandler;

            if (asBitStringHandler != null)
            {
                // BitString requires a special array handler which returns bool or BitArray
                arrayHandler = new BitStringArrayHandler(asBitStringHandler);
            }
            else if (elementHandler is ITypeHandlerWithPsv)
            {
                var arrayHandlerType = typeof(ArrayHandlerWithPsv <,>).MakeGenericType(elementHandler.GetFieldType(), elementHandler.GetProviderSpecificFieldType());
                arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler);
            }
            else
            {
                var arrayHandlerType = typeof(ArrayHandler <>).MakeGenericType(elementHandler.GetFieldType());
                arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler);
            }

            arrayHandler.PgName        = "array";
            arrayHandler.OID           = backendType.OID;
            _oidIndex[backendType.OID] = arrayHandler;

            if (elementHandler is IEnumHandler)
            {
                if (_byEnumTypeAsArray == null)
                {
                    _byEnumTypeAsArray = new Dictionary <Type, TypeHandler>();
                }
                var enumType = elementHandler.GetType().GetGenericArguments()[0];
                Contract.Assert(enumType.GetTypeInfo().IsEnum);
                _byEnumTypeAsArray[enumType] = arrayHandler;
            }
            else
            {
                _byNpgsqlDbType[NpgsqlDbType.Array | elementHandler.NpgsqlDbType] = arrayHandler;
            }
        }