Class NpgsqlTypeHandler<TDefault>
- Namespace
- Npgsql.TypeHandling
- Assembly
- Npgsql.dll
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.
public abstract class NpgsqlTypeHandler<TDefault> : NpgsqlTypeHandler, INpgsqlTypeHandler<TDefault>
Type Parameters
TDefaultThe default CLR type that this handler will read and write. For example, calling GetValue(int) on a column with this handler will return a value with type
TDefault. Type handlers can support additional types by implementing INpgsqlTypeHandler<T>.
- Inheritance
-
NpgsqlTypeHandler<TDefault>
- Implements
-
INpgsqlTypeHandler<TDefault>
- Derived
-
NpgsqlSimpleTypeHandler<TDefault>
- Inherited Members
Constructors
NpgsqlTypeHandler()
Constructs an NpgsqlTypeHandler<TDefault>.
protected NpgsqlTypeHandler()
Methods
CreateArrayHandler(PostgresType)
Creates a type handler for arrays of this handler's type.
public override ArrayHandler CreateArrayHandler(PostgresType arrayBackendType)
Parameters
arrayBackendTypePostgresType
Returns
CreateRangeHandler(PostgresType)
Creates a type handler for ranges of this handler's type.
public override RangeHandler CreateRangeHandler(PostgresType rangeBackendType)
Parameters
rangeBackendTypePostgresType
Returns
Read(NpgsqlReadBuffer, int, bool, FieldDescription)
Reads a value of type TDefault with the given length from the provided buffer,
using either sync or async I/O.
public abstract ValueTask<TDefault> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
bufNpgsqlReadBufferThe buffer from which to read.
lenintThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
asyncboolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescriptionFieldDescriptionAdditional PostgreSQL information about the type, such as the length in varchar(30).
Returns
- ValueTask<TDefault>
The fully-read value.
Read<TAny>(NpgsqlReadBuffer, int, bool, 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, int, bool, FieldDescription) - but may do
so in exceptional cases where reading of arbitrary types is required.
protected override ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
bufNpgsqlReadBufferThe buffer from which to read.
lenintThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
asyncboolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescriptionFieldDescriptionAdditional PostgreSQL information about the type, such as the length in varchar(30).
Returns
- ValueTask<TAny>
The fully-read value.
Type Parameters
TAny
ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)
Called to validate and get the length of a value of a generic NpgsqlParameter<T>.
public abstract int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueTDefaultlengthCacheNpgsqlLengthCacheparameterNpgsqlParameter
Returns
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.
protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueTAnylengthCacheNpgsqlLengthCacheparameterNpgsqlParameter
Returns
Type Parameters
TAny
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.
protected override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueobjectlengthCacheNpgsqlLengthCacheparameterNpgsqlParameter
Returns
Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Called to write the value of a generic NpgsqlParameter<T>.
public abstract Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
valueTDefaultbufNpgsqlWriteBufferlengthCacheNpgsqlLengthCacheparameterNpgsqlParameterasyncbool
Returns
WriteObjectWithLength(object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Called to write the value of a non-generic NpgsqlParameter. Type handlers generally don't need to override this.
protected override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
valueobjectbufNpgsqlWriteBufferlengthCacheNpgsqlLengthCacheparameterNpgsqlParameterasyncbool
Returns
WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
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 WriteWithLengthInternal<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)).
protected virtual Task WriteWithLength<TAny>(TAny value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
valueTAnybufNpgsqlWriteBufferlengthCacheNpgsqlLengthCacheparameterNpgsqlParameterasyncbool
Returns
Type Parameters
TAny