public override async ValueTask Read(TComposite composite, NpgsqlReadBuffer buffer, bool async, CancellationToken cancellationToken = default) { if (_set == null) { ThrowHelper.ThrowInvalidOperationException_NoPropertySetter(typeof(TComposite), MemberInfo); } await buffer.Ensure(sizeof(uint) + sizeof(int), async, cancellationToken); var oid = buffer.ReadUInt32(); Debug.Assert(oid == PostgresType.OID); var length = buffer.ReadInt32(); if (length == -1) { return; } var value = NullableHandler <TMember> .Exists ? await NullableHandler <TMember> .ReadAsync(_handler, buffer, length, async, cancellationToken : cancellationToken) : await _handler.Read <TMember>(buffer, length, async, cancellationToken : cancellationToken); _set(composite, value); }
static NullableHandler() { UnderlyingType = Nullable.GetUnderlyingType(typeof(T)); if (UnderlyingType == null) { return; } Read = NullableHandler.CreateDelegate <ReadDelegate <T> >(UnderlyingType, NullableHandler.ReadMethod); ReadAsync = NullableHandler.CreateDelegate <ReadAsyncDelegate <T> >(UnderlyingType, NullableHandler.ReadAsyncMethod); ValidateAndGetLength = NullableHandler.CreateDelegate <ValidateAndGetLengthDelegate <T> >(UnderlyingType, NullableHandler.ValidateMethod); WriteAsync = NullableHandler.CreateDelegate <WriteAsyncDelegate <T> >(UnderlyingType, NullableHandler.WriteAsyncMethod); }
public override async Task Write(TComposite composite, NpgsqlWriteBuffer buffer, NpgsqlLengthCache?lengthCache, bool async, CancellationToken cancellationToken = default) { if (_get == null) { ThrowHelper.ThrowInvalidOperationException_NoPropertyGetter(typeof(TComposite), MemberInfo); } if (buffer.WriteSpaceLeft < sizeof(int)) { await buffer.Flush(async, cancellationToken); } buffer.WriteUInt32(PostgresType.OID); await(NullableHandler <TMember> .Exists ? NullableHandler <TMember> .WriteAsync(_handler, _get(ref composite), buffer, lengthCache, null, async, cancellationToken) : _handler.WriteWithLengthInternal(_get(ref composite), buffer, lengthCache, null, async, cancellationToken)); }
public override int ValidateAndGetLength(TComposite composite, ref NpgsqlLengthCache?lengthCache) { if (_get == null) { ThrowHelper.ThrowInvalidOperationException_NoPropertyGetter(typeof(TComposite), MemberInfo); } var value = _get(composite); if (value == null) { return(0); } return(NullableHandler <TMember> .Exists ? NullableHandler <TMember> .ValidateAndGetLength(_handler, value, ref lengthCache, null) : _handler.ValidateAndGetLength(value, ref lengthCache, null)); }