Class NpgsqlTypeHandler
- Namespace
- Npgsql.TypeHandling
- Assembly
- Npgsql.dll
Base class for all type handlers, which read and write CLR types into their PostgreSQL binary representation. Type handler writers shouldn't inherit from this class, inherit NpgsqlTypeHandler or NpgsqlSimpleTypeHandler<TDefault> instead.
public abstract class NpgsqlTypeHandler
- Inheritance
-
NpgsqlTypeHandler
- Derived
- Inherited Members
Constructors
NpgsqlTypeHandler()
protected NpgsqlTypeHandler()
Methods
CreateArrayHandler(PostgresType)
Creates a type handler for arrays of this handler's type.
public abstract ArrayHandler CreateArrayHandler(PostgresType arrayBackendType)
Parameters
arrayBackendTypePostgresType
Returns
CreateConversionButNoParamException(Type)
Used to create an exception when the provided type can be converted and written, but an instance of NpgsqlParameter is required for caching of the converted value (in ConvertedValue.
protected Exception CreateConversionButNoParamException(Type clrType)
Parameters
clrTypeType
Returns
CreateRangeHandler(PostgresType)
Creates a type handler for ranges of this handler's type.
public abstract RangeHandler CreateRangeHandler(PostgresType rangeBackendType)
Parameters
rangeBackendTypePostgresType
Returns
Read<TAny>(NpgsqlReadBuffer, int, bool, FieldDescription)
Reads a value of type TAny with the given length from the provided buffer,
using either sync or async I/O.
protected abstract 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<TAny>(TAny, ref NpgsqlLengthCache, NpgsqlParameter)
Called to validate and get the length of a value of a generic NpgsqlParameter<T>.
protected abstract int ValidateAndGetLength<TAny>(TAny value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueTAnylengthCacheNpgsqlLengthCacheparameterNpgsqlParameter
Returns
Type Parameters
TAny
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.
protected abstract int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
valueobjectThe value to be written to PostgreSQL
lengthCacheNpgsqlLengthCacheIf 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.
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.
WriteObjectWithLength(object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)
Writes a value to the provided buffer, using either sync or async I/O.
protected abstract Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
valueobjectThe value to write.
bufNpgsqlWriteBufferThe buffer to which to write.
lengthCacheNpgsqlLengthCacheparameterNpgsqlParameterThe NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).
asyncboolIf I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.