Search Results for

    Show / Hide Table of Contents

    Class NpgsqlTypeHandler

    Base class for all type handlers, which read and write CLR types into their PostgreSQL binary representation. Type handler writers shouldn't inherit from this class, inherit NpgsqlTypeHandler or NpgsqlSimpleTypeHandler<TDefault> instead.

    Inheritance
    Object
    NpgsqlTypeHandler
    ArrayHandler
    RangeHandler<TSubtype>
    NpgsqlTypeHandler<TDefault>
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Npgsql.Internal.TypeHandling
    Assembly: Npgsql.dll
    Syntax
    public abstract class NpgsqlTypeHandler

    Constructors

    NpgsqlTypeHandler(PostgresType)

    Declaration
    protected NpgsqlTypeHandler(PostgresType postgresType)
    Parameters
    Type Name Description
    PostgresType postgresType

    Properties

    PostgresType

    The PostgreSQL type handled by this type handler.

    Declaration
    public PostgresType PostgresType { get; }
    Property Value
    Type Description
    PostgresType

    Methods

    CreateArrayHandler(PostgresArrayType, ArrayNullabilityMode)

    Creates a type handler for arrays of this handler's type.

    Declaration
    public abstract NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
    Parameters
    Type Name Description
    PostgresArrayType pgArrayType
    ArrayNullabilityMode arrayNullabilityMode
    Returns
    Type Description
    NpgsqlTypeHandler

    CreateConversionButNoParamException(Type)

    Used to create an exception when the provided type can be converted and written, but an instance of NpgsqlParameter is required for caching of the converted value (in ConvertedValue.

    Declaration
    protected Exception CreateConversionButNoParamException(Type clrType)
    Parameters
    Type Name Description
    Type clrType
    Returns
    Type Description
    Exception

    CreateMultirangeHandler(PostgresMultirangeType)

    Creates a type handler for multiranges of this handler's type.

    Declaration
    public abstract NpgsqlTypeHandler CreateMultirangeHandler(PostgresMultirangeType pgMultirangeType)
    Parameters
    Type Name Description
    PostgresMultirangeType pgMultirangeType
    Returns
    Type Description
    NpgsqlTypeHandler

    CreateRangeHandler(PostgresType)

    Creates a type handler for ranges of this handler's type.

    Declaration
    public abstract NpgsqlTypeHandler CreateRangeHandler(PostgresType pgRangeType)
    Parameters
    Type Name Description
    PostgresType pgRangeType
    Returns
    Type Description
    NpgsqlTypeHandler

    GetFieldType(FieldDescription)

    Declaration
    public abstract Type GetFieldType(FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    FieldDescription fieldDescription
    Returns
    Type Description
    Type

    GetProviderSpecificFieldType(FieldDescription)

    Declaration
    public abstract Type GetProviderSpecificFieldType(FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    FieldDescription fieldDescription
    Returns
    Type Description
    Type

    Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)

    Version of Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription) that's called when we know the entire value is already buffered in memory (i.e. in non-sequential mode).

    Declaration
    public TAny Read<TAny>(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    FieldDescription fieldDescription
    Returns
    Type Description
    TAny
    Type Parameters
    Name Description
    TAny

    Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Reads a value of type TAny with the given length from the provided buffer, using either sync or async I/O.

    Declaration
    protected async ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf

    The buffer from which to read.

    Int32 len

    The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.

    Boolean async

    If I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.

    FieldDescription fieldDescription

    Additional PostgreSQL information about the type, such as the length in varchar(30).

    Returns
    Type Description
    ValueTask<TAny>

    The fully-read value.

    Type Parameters
    Name Description
    TAny

    ReadAsObject(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Reads a column as the type handler's default read type. If it is not already entirely in memory, sync or async I/O will be performed as specified by async.

    Declaration
    public abstract ValueTask<object> ReadAsObject(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<Object>

    ReadCustom<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

    Declaration
    protected virtual ValueTask<TAny> ReadCustom<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
    Parameters
    Type Name Description
    NpgsqlReadBuffer buf
    Int32 len
    Boolean async
    FieldDescription fieldDescription
    Returns
    Type Description
    ValueTask<TAny>
    Type Parameters
    Name Description
    TAny

    ValidateAndGetLength<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)

    Called to validate and get the length of a value of a generic NpgsqlParameter<T>.

    null and DBNull must be handled before calling into this.

    Declaration
    protected int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    TAny value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    TAny

    ValidateAndGetLengthCustom<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)

    Declaration
    protected virtual int ValidateAndGetLengthCustom<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    TAny value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    TAny

    ValidateObjectAndGetLength(Object, ref NpgsqlLengthCache, NpgsqlParameter)

    Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception shold be thrown. Also returns the byte length needed to write the value.

    Declaration
    public abstract int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    Object value

    The value to be written to PostgreSQL

    NpgsqlLengthCache lengthCache

    If the byte length calculation is costly (e.g. for UTF-8 strings), its result can be stored in the length cache to be reused in the writing process, preventing recalculation.

    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Returns
    Type Description
    Int32

    The number of bytes required to write the value.

    WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Writes a value to the provided buffer, using either sync or async I/O.

    Declaration
    public abstract Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    Object value

    The value to write.

    NpgsqlWriteBuffer buf

    The buffer to which to write.

    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter

    The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

    Boolean async

    If I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is None.

    Returns
    Type Description
    Task

    WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Called to write the value of a generic NpgsqlParameter<T>.

    Declaration
    public async Task WriteWithLength<TAny>(TAny value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    TAny value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    TAny

    WriteWithLengthCustom<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)

    Typically does not need to be overridden by type handlers, but may be needed in some cases (e.g. ArrayHandler. Note that this method assumes it can write 4 bytes of length (already verified by WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)).

    Declaration
    protected virtual Task WriteWithLengthCustom<TAny>(TAny value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    TAny value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    TAny
    In This Article
    Back to top © Copyright 2022 The Npgsql Development Team