Class NpgsqlSimpleTypeHandler<TDefault>
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.
Inherited Members
Namespace: Npgsql.Internal.TypeHandling
Assembly: Npgsql.dll
Syntax
public abstract class NpgsqlSimpleTypeHandler<TDefault> : NpgsqlTypeHandler<TDefault>, INpgsqlTypeHandler<TDefault>, INpgsqlSimpleTypeHandler<TDefault>
Type Parameters
Name | Description |
---|---|
TDefault | The default CLR type that this handler will read and write. For example, calling GetValue(Int32)
on a column with this handler will return a value with type |
Constructors
NpgsqlSimpleTypeHandler(PostgresType)
Declaration
protected NpgsqlSimpleTypeHandler(PostgresType postgresType)
Parameters
Type | Name | Description |
---|---|---|
PostgresType | postgresType |
Methods
Read(NpgsqlReadBuffer, Int32, 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.
Declaration
public abstract TDefault Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | The buffer from which to read. |
Int32 | len | The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed. |
FieldDescription | fieldDescription | Additional PostgreSQL information about the type, such as the length in varchar(30). |
Returns
Type | Description |
---|---|
TDefault | The fully-read value. |
Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
public sealed override ValueTask<TDefault> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | |
Int32 | len | |
Boolean | async | |
FieldDescription | fieldDescription |
Returns
Type | Description |
---|---|
ValueTask<TDefault> |
Overrides
ValidateAndGetLength(TDefault, ref NpgsqlLengthCache, NpgsqlParameter)
Simple type handlers override ValidateAndGetLength(TDefault, NpgsqlParameter) instead of this.
Declaration
public sealed override int ValidateAndGetLength(TDefault value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter |
Returns
Type | Description |
---|---|
Int32 |
Overrides
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.
Declaration
public abstract int ValidateAndGetLength(TDefault value, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | The value to be written to PostgreSQL |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Returns
Type | Description |
---|---|
Int32 | The number of bytes required to write the value. |
Write(TDefault, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
Simple type handlers override Write(TDefault, NpgsqlWriteBuffer, NpgsqlParameter) instead of this.
Declaration
public sealed override Task Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | |
NpgsqlWriteBuffer | buf | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter | |
Boolean | async | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
Overrides
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.
Declaration
public abstract void Write(TDefault value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
TDefault | value | The value to write. |
NpgsqlWriteBuffer | buf | The buffer to which to write. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |