Class NpgsqlSimpleTypeHandler<TDefault>
- Namespace
- Npgsql.TypeHandling
- Assembly
- Npgsql.dll
Base class for all simple type handlers, which read and write short, non-arbitrary lengthed values to PostgreSQL. Provides a simpler API to implement when compared to NpgsqlTypeHandler - Npgsql takes care of all I/O before calling into this type, so no I/O needs to be performed by it.
public abstract class NpgsqlSimpleTypeHandler<TDefault> : NpgsqlTypeHandler<TDefault>, INpgsqlTypeHandler<TDefault>, INpgsqlSimpleTypeHandler<TDefault>
Type Parameters
TDefault
The 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>NpgsqlSimpleTypeHandler<TDefault>
- Implements
-
INpgsqlTypeHandler<TDefault>INpgsqlSimpleTypeHandler<TDefault>
- Derived
- Inherited Members
Constructors
NpgsqlSimpleTypeHandler()
Constructs an NpgsqlSimpleTypeHandler<TDefault>.
protected NpgsqlSimpleTypeHandler()
Methods
Read(NpgsqlReadBuffer, int, FieldDescription)
Reads a value of type TDefault
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.
public abstract TDefault Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
Parameters
buf
NpgsqlReadBufferThe buffer from which to read.
len
intThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
fieldDescription
FieldDescriptionAdditional PostgreSQL information about the type, such as the length in varchar(30).
Returns
- TDefault
The fully-read value.
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. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>,
override Read(NpgsqlReadBuffer, int, FieldDescription).
public override sealed ValueTask<TDefault> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
buf
NpgsqlReadBufferThe buffer from which to read.
len
intThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
async
boolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescription
FieldDescriptionAdditional 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. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>.
protected override sealed ValueTask<TAny> Read<TAny>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
buf
NpgsqlReadBufferThe buffer from which to read.
len
intThe byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.
async
boolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.
fieldDescription
FieldDescriptionAdditional 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)
Simple type handlers override ValidateAndGetLength(TDefault, NpgsqlParameter) instead of this.
public override sealed int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
value
TDefaultlengthCache
NpgsqlLengthCacheparameter
NpgsqlParameter
Returns
ValidateAndGetLength(TDefault, 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.
public abstract int ValidateAndGetLength(TDefault value, NpgsqlParameter parameter)
Parameters
value
TDefaultThe value to be written to PostgreSQL
parameter
NpgsqlParameterThe 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.
ValidateAndGetLength<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)
This method is sealed, override ValidateAndGetLength(TDefault, NpgsqlParameter).
protected override int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
value
TAnylengthCache
NpgsqlLengthCacheparameter
NpgsqlParameter
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
value
objectlengthCache
NpgsqlLengthCacheparameter
NpgsqlParameter
Returns
Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Simple type handlers override Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter) instead of this.
public override sealed Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
value
TDefaultbuf
NpgsqlWriteBufferlengthCache
NpgsqlLengthCacheparameter
NpgsqlParameterasync
bool
Returns
Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter)
Writes a value to the provided buffer, with the assumption that there is enough space in the buffer (no I/O will occur). The Npgsql core will have taken care of that.
public abstract void Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)
Parameters
value
TDefaultThe value to write.
buf
NpgsqlWriteBufferThe buffer to which to write.
parameter
NpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
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
value
objectbuf
NpgsqlWriteBufferlengthCache
NpgsqlLengthCacheparameter
NpgsqlParameterasync
bool