Table of Contents

Class ArrayHandler<TElement>

Namespace
Npgsql.TypeHandlers
Assembly
Npgsql.dll

Base class for all type handlers which handle PostgreSQL arrays.

public class ArrayHandler<TElement> : ArrayHandler

Type Parameters

TElement
Inheritance
ArrayHandler<TElement>
Inherited Members

Remarks

Constructors

ArrayHandler(NpgsqlTypeHandler, int)

public ArrayHandler(NpgsqlTypeHandler elementHandler, int lowerBound = 1)

Parameters

elementHandler NpgsqlTypeHandler
lowerBound int

Methods

ReadArray<T>(NpgsqlReadBuffer, bool)

protected ValueTask<Array> ReadArray<T>(NpgsqlReadBuffer buf, bool async)

Parameters

buf NpgsqlReadBuffer
async bool

Returns

ValueTask<Array>

Type Parameters

T

ReadList<T>(NpgsqlReadBuffer, bool)

protected ValueTask<List<T>> ReadList<T>(NpgsqlReadBuffer buf, bool async)

Parameters

buf NpgsqlReadBuffer
async bool

Returns

ValueTask<List<T>>

Type Parameters

T

Read<TAny>(NpgsqlReadBuffer, int, bool, FieldDescription)

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

protected override ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)

Parameters

buf NpgsqlReadBuffer

The buffer from which to read.

len int

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

async bool

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

ValueTask<TAny>

The fully-read value.

Type Parameters

TAny

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

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

protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)

Parameters

value TAny
lengthCache NpgsqlLengthCache
parameter NpgsqlParameter

Returns

int

Type Parameters

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.

protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter = null)

Parameters

value object

The value to be written to PostgreSQL

lengthCache NpgsqlLengthCache

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.

parameter NpgsqlParameter

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

Returns

int

The number of bytes required to write the value.

WriteObjectWithLength(object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)

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

protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)

Parameters

value object

The value to write.

buf NpgsqlWriteBuffer

The buffer to which to write.

lengthCache NpgsqlLengthCache
parameter NpgsqlParameter

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

async bool

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

Returns

Task