Show / Hide Table of Contents

Class RangeHandler<TElement>

A type handler for PostgreSQL range types.

Inheritance
System.Object
NpgsqlTypeHandler
RangeHandler
RangeHandler<TElement>
Implements
INpgsqlTypeHandler<NpgsqlRange<TElement>>
Inherited Members
RangeHandler.CreateRangeHandler(PostgresRangeType)
NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Npgsql.TypeHandlers
Assembly: Npgsql.dll
Syntax
public class RangeHandler<TElement> : RangeHandler, INpgsqlTypeHandler<NpgsqlRange<TElement>>
Type Parameters
Name Description
TElement

the range subtype

Remarks

See http://www.postgresql.org/docs/current/static/rangetypes.html.

The type handler API allows customizing Npgsql's behavior in powerful ways. However, although it is public, it should be considered somewhat unstable, and may change in breaking ways, including in non-major releases. Use it at your own risk.

Constructors

RangeHandler(PostgresType, NpgsqlTypeHandler)

Declaration
public RangeHandler(PostgresType rangePostgresType, NpgsqlTypeHandler elementHandler)
Parameters
Type Name Description
PostgresType rangePostgresType
NpgsqlTypeHandler elementHandler

Methods

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)

Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)

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

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

The buffer from which to read.

System.Int32 len

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

System.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<NpgsqlRange<TElement>>

The fully-read value.

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.

System.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)

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 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.

System.Int32 len

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

System.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)

ValidateAndGetLength(NpgsqlRange<TElement>, 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 should be thrown. Also returns the byte length needed to write the value.

Declaration
public int ValidateAndGetLength(NpgsqlRange<TElement> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
NpgsqlRange<TElement> value
NpgsqlLengthCache lengthCache

A cache where the length calculated during the validation phase can be stored for use at the writing phase.

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
System.Int32

The number of bytes required to write the value.

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

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

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
System.Int32
Type Parameters
Name Description
TAny
Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter)

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
protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type Name Description
System.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
System.Int32

The number of bytes required to write the value.

Overrides
NpgsqlTypeHandler.ValidateObjectAndGetLength(Object, ref NpgsqlLengthCache, NpgsqlParameter)

Write(NpgsqlRange<TElement>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Writes a value to the provided buffer.

Declaration
public Task Write(NpgsqlRange<TElement> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
NpgsqlRange<TElement> value
NpgsqlWriteBuffer buf

The buffer to which to write.

NpgsqlLengthCache lengthCache

A cache where the length calculated during the validation phase can be stored for use at the writing phase.

NpgsqlParameter parameter

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

System.Boolean async

If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.

Returns
Type Description
System.Threading.Tasks.Task

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

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

Declaration
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.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).

System.Boolean async

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

Returns
Type Description
System.Threading.Tasks.Task
Overrides
NpgsqlTypeHandler.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Implements

INpgsqlTypeHandler<T>
In This Article
Back to top Generated by DocFX