Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/Npgsql/Internal/TypeHandlers/MultirangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace Npgsql.Internal.TypeHandlers;

public partial class MultirangeHandler<TSubtype> : NpgsqlTypeHandler<NpgsqlRange<TSubtype>[]>,
// NOTE: This cannot inherit from NpgsqlTypeHandler<NpgsqlRange<TSubtype>[]>, since that triggers infinite generic recursion in Native AOT
public partial class MultirangeHandler<TSubtype> : NpgsqlTypeHandler,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I think I did this for ranges in #4095, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's where I got the idea from.

INpgsqlTypeHandler<NpgsqlRange<TSubtype>[]>,
INpgsqlTypeHandler<List<NpgsqlRange<TSubtype>>>
{
/// <summary>
Expand All @@ -22,7 +24,7 @@ public MultirangeHandler(PostgresMultirangeType pgMultirangeType, RangeHandler<T
: base(pgMultirangeType)
=> RangeHandler = rangeHandler;

public override ValueTask<NpgsqlRange<TSubtype>[]> Read(
public ValueTask<NpgsqlRange<TSubtype>[]> Read(
NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null)
=> ReadMultirangeArray<TSubtype>(buf, len, async, fieldDescription);

Expand Down Expand Up @@ -64,7 +66,10 @@ protected async ValueTask<List<NpgsqlRange<TAnySubtype>>> ReadMultirangeList<TAn
return multirange;
}

public override int ValidateAndGetLength(NpgsqlRange<TSubtype>[] value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter)
public override async ValueTask<object> ReadAsObject(NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null)
=> await Read(buf, len, async, fieldDescription);

public int ValidateAndGetLength(NpgsqlRange<TSubtype>[] value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter)
=> ValidateAndGetLengthMultirange(value, ref lengthCache, parameter);

public int ValidateAndGetLength(List<NpgsqlRange<TSubtype>> value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter)
Expand All @@ -89,7 +94,7 @@ protected int ValidateAndGetLengthMultirange<TAnySubtype>(
return sum;
}

public override Task Write(
public Task Write(
NpgsqlRange<TSubtype>[] value,
NpgsqlWriteBuffer buf,
NpgsqlLengthCache? lengthCache,
Expand Down Expand Up @@ -123,6 +128,21 @@ public async Task WriteMultirange<TAnySubtype>(
for (var i = 0; i < value.Count; i++)
await RangeHandler.WriteWithLength(value[i], buf, lengthCache, parameter: null, async, cancellationToken);
}

public override Type GetFieldType(FieldDescription? fieldDescription = null) => typeof(NpgsqlRange<TSubtype>[]);
public override Type GetProviderSpecificFieldType(FieldDescription? fieldDescription = null) => typeof(NpgsqlRange<TSubtype>[]);

/// <inheritdoc />
public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
=> throw new NotSupportedException();

/// <inheritdoc />
public override NpgsqlTypeHandler CreateRangeHandler(PostgresType pgRangeType)
=> throw new NotSupportedException();

/// <inheritdoc />
public override NpgsqlTypeHandler CreateMultirangeHandler(PostgresMultirangeType pgMultirangeType)
=> throw new NotSupportedException();
}

public class MultirangeHandler<TSubtype1, TSubtype2> : MultirangeHandler<TSubtype1>,
Expand Down
1 change: 1 addition & 0 deletions src/Npgsql/NpgsqlConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
#region ICustomTypeDescriptor

/// <inheritdoc />
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
protected override void GetProperties(Hashtable propertyDescriptors)
{
// Tweak which properties are exposed via TypeDescriptor. This affects the VS DDEX
Expand Down