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
System.Object
NpgsqlTypeHandler<TDefault>
Inherited Members
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()
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 System.Data.Common.DbDataReader.GetValue(System.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
NpgsqlTypeHandler()
Declaration
protected NpgsqlTypeHandler()
Methods
CreateArrayHandler(PostgresType)
Creates a type handler for arrays of this handler's type.
Declaration
public override ArrayHandler CreateArrayHandler(PostgresType arrayBackendType)
Parameters
Returns
Overrides
CreateRangeHandler(PostgresType)
Creates a type handler for ranges of this handler's type.
Declaration
public override RangeHandler CreateRangeHandler(PostgresType rangeBackendType)
Parameters
Returns
Overrides
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.
|
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 |
System.Threading.Tasks.ValueTask<TDefault> |
The fully-read value.
|
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.
|
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 |
System.Threading.Tasks.ValueTask<TAny> |
The fully-read value.
|
Type Parameters
Overrides
ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)
Declaration
public abstract int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Returns
Type |
Description |
System.Int32 |
|
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
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter)
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
Returns
Type |
Description |
System.Int32 |
|
Overrides
Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
Declaration
public abstract Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
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
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Overrides
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
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Type Parameters
Implements