Search Results for

    Show / Hide Table of Contents

    Class NpgsqlTypeHandler<TDefault>

    Base class for all type handlers, which read and write CLR types into their PostgreSQL binary representation. Unless your type is arbitrary-length, consider inheriting from NpgsqlSimpleTypeHandler<TDefault> instead.

    Inheritance
    Object
    NpgsqlTypeHandler
    NpgsqlTypeHandler<TDefault>
    BitStringHandler
    ByteaHandler
    TsQueryHandler
    TsVectorHandler
    PathHandler
    PolygonHandler
    HstoreHandler
    JsonHandler
    TextHandler
    NpgsqlSimpleTypeHandler<TDefault>
    Implements
    INpgsqlTypeHandler<TDefault>
    Inherited Members
    NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Npgsql.TypeHandling
    Assembly: Npgsql.dll
    Syntax
    public abstract class NpgsqlTypeHandler<TDefault> : NpgsqlTypeHandler, INpgsqlTypeHandler<TDefault>
    Type Parameters
    Name Description
    TDefault

    The default CLR type that this handler will read and write. For example, calling GetValue(Int32) on a column with this handler will return a value with type TDefault. Type handlers can support additional types by implementing INpgsqlTypeHandler<T>.

    Constructors

    | Improve this Doc

    NpgsqlTypeHandler(PostgresType)

    Constructs an NpgsqlTypeHandler<TDefault>.

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

    Methods

    | Improve this Doc

    CreateArrayHandler(PostgresArrayType)

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

    Declaration
    public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType)
    Parameters
    Type Name Description
    PostgresArrayType arrayBackendType
    Returns
    Type Description
    ArrayHandler
    Overrides
    NpgsqlTypeHandler.CreateArrayHandler(PostgresArrayType)
    | Improve this Doc

    CreateRangeHandler(PostgresRangeType)

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

    Declaration
    public override RangeHandler CreateRangeHandler(PostgresRangeType rangeBackendType)
    Parameters
    Type Name Description
    PostgresRangeType rangeBackendType
    Returns
    Type Description
    RangeHandler
    Overrides
    NpgsqlTypeHandler.CreateRangeHandler(PostgresRangeType)
    | Improve this Doc

    Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

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

    Declaration
    public abstract ValueTask<TDefault> Read(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<TDefault>

    The fully-read value.

    | Improve this Doc

    Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)

    Reads a value of type TAny with the given length from the provided buffer, with the assumption that it is entirely present in the provided memory buffer and no I/O will be required. This can save the overhead of async functions and improves performance.

    Declaration
    public override TAny Read<TAny>(NpgsqlReadBuffer buf, int len, 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.

    FieldDescription fieldDescription

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

    Returns
    Type Description
    TAny

    The fully-read value.

    Type Parameters
    Name Description
    TAny
    Overrides
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
    | Improve this Doc

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

    Reads a value of type TDefault with the given length from the provided buffer, using either sync or async I/O. Type handlers typically don't need to override this - override Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription) - but may do so in exceptional cases where reading of arbitrary types is required.

    Declaration
    protected override 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
    Overrides
    NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
    | Improve this Doc

    ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)

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

    Declaration
    public abstract int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    TDefault value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    | Improve this Doc

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

    Called to validate and get the length of a value of an arbitrary type. Checks that the current handler supports that type and throws an exception otherwise.

    Declaration
    protected override 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
    Overrides
    Npgsql.TypeHandling.NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter)
    | Improve this Doc

    ValidateObjectAndGetLength(Object, ref NpgsqlLengthCache, NpgsqlParameter)

    Called to validate and get the length of a value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.

    Declaration
    protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
    Parameters
    Type Name Description
    Object value
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Returns
    Type Description
    Int32
    Overrides
    NpgsqlTypeHandler.ValidateObjectAndGetLength(Object, ref NpgsqlLengthCache, NpgsqlParameter)
    | Improve this Doc

    Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

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

    Declaration
    public abstract Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
    Parameters
    Type Name Description
    TDefault value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    Returns
    Type Description
    Task
    | Improve this Doc

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

    Called to write the value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.

    Declaration
    protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
    Parameters
    Type Name Description
    Object value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    Returns
    Type Description
    Task
    Overrides
    NpgsqlTypeHandler.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
    | Improve this Doc

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

    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 Npgsql.TypeHandling.NpgsqlTypeHandler`1.WriteWithLengthInternal``1(``0,Npgsql.NpgsqlWriteBuffer,Npgsql.NpgsqlLengthCache,Npgsql.NpgsqlParameter,System.Boolean)).

    Declaration
    protected virtual Task WriteWithLength<TAny>(TAny value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
    Parameters
    Type Name Description
    TAny value
    NpgsqlWriteBuffer buf
    NpgsqlLengthCache lengthCache
    NpgsqlParameter parameter
    Boolean async
    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    TAny

    Implements

    INpgsqlTypeHandler<T>
    • Improve this Doc
    In This Article
    Back to top © Copyright 2021 The Npgsql Development Team