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
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>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
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.
fieldDescriptionFieldDescriptionAdditional 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
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. This method is sealed for NpgsqlSimpleTypeHandler<TDefault>.
protected override sealed 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)
Simple type handlers override ValidateAndGetLength(TDefault, NpgsqlParameter) instead of this.
public override sealed int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueTDefaultlengthCacheNpgsqlLengthCacheparameterNpgsqlParameter
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
valueTDefaultThe value to be written to PostgreSQL
parameterNpgsqlParameterThe 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
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)
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
valueTDefaultbufNpgsqlWriteBufferlengthCacheNpgsqlLengthCacheparameterNpgsqlParameterasyncbool
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
valueTDefaultThe value to write.
bufNpgsqlWriteBufferThe buffer to which to write.
parameterNpgsqlParameterThe 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
valueobjectbufNpgsqlWriteBufferlengthCacheNpgsqlLengthCacheparameterNpgsqlParameterasyncbool